Execute a SOAP request from Powershell

Web services are everywhere such as SOAP requests, WCF services and traditional ASMX asp.net web services.   I was working on a task recently we needed to call a SOAP service from a powershell script.  A good friend of mine passed this snippet to me.  If you want to test SOAP requests, using SOAP UI  This allows you to build soap requests.   Hope this helps.

These return XML objects with the server’s response.

function Execute-SOAPRequest
        [Xml]    $SOAPRequest,
        [String] $URL
        write-host “Sending SOAP Request To Server: $URL”
        $soapWebRequest = [System.Net.WebRequest]::Create($URL)

        $soapWebRequest.ContentType = “text/xml;charset=`”utf-8`””
        $soapWebRequest.Accept      = “text/xml”
        $soapWebRequest.Method      = “POST”
        write-host “Initiating Send.”
        $requestStream = $soapWebRequest.GetRequestStream()
        write-host “Send Complete, Waiting For Response.”
        $resp = $soapWebRequest.GetResponse()
        $responseStream = $resp.GetResponseStream()
        $soapReader = [System.IO.StreamReader]($responseStream)
        $ReturnXml = [Xml] $soapReader.ReadToEnd()
        write-host “Response Received.”

        return $ReturnXml

function Execute-SOAPRequestFromFile
        [String] $SOAPRequestFile,
        [String] $URL
        write-host “Reading and converting file to XmlDocument: $SOAPRequestFile”
        $SOAPRequest = [Xml](Get-Content $SOAPRequestFile)

        return $(Execute-SOAPRequest $SOAPRequest $URL)


Steve Schofield
Microsoft MVP – IIS

Chapter 1 from Microsoft Visual C# 2008: An Introduction to Object-Oriented Programming down

Almost done with Chapter 1, few questions on things like Polymorphism, few terms that I have to remember.  The concept of OOP isn’t as foreign as it was in the past, I call that progress.  I even wrote a couple of Console applications with my 11 year old.  Man would I give anything to be young and learn OOP. I recall those days being a spunge.  I’m sure this will get A LOT harder for a newbie.  I’m willing to forge ahead.  I think before class on Thursday, I should probably read the chapter again.  The homework itself wasn’t too bad.  A couple of review questions I stumbled on was OO related.  Off to see the teacher ๐Ÿ™‚  Mostly the questions where asking sample content and what should the class name be.  Umm….

Here is a link to the book  The book so far is written very nicely, I should have bought the book from Amazon, I would have saved 4 bucks, and gotten it brand new. ๐Ÿ˜   The next book I write, I should target colleges, they sell for a lot more than normal geeky books.  I’m used to the 30/40 dollar range. 

Stay tuned.

Steve Schofield
Microsoft MVP – IIS

C# programming class (Yuppers, I’m in skool again)

Have you ever gotten excited about learning something and wanted to share?!?! I’ll probably write a few posts about my experiences.  I’m taking a “Introduction to C# Programming Class” at Grand Rapids Community College.  It’s been a while since I was in a college setting (and book prices are insane, the next book I write will be for colleges).  I graduated 15+ years ago from college.  And I went for Business.  That’s another story.  If you follow my blog, you probably wonder why I would take a C# programming class.  I’m not a full-time programmer nor have I had formal  a programming class, until now.   I’ve always respected developers who can develop (notice I didn’t say “just code”).  They know how to design, architect and all around perform code miracles.  I don’t expect the class to make me the next guru. I’d like to get some foundational principals that can be used in future projects. 

The first class tonight (1/7) covered the basics, history of C# and a few others.  It was cool!  As the instructor was talking about the history portion.  I remember being at Microsoft in July of 2000 listening to Anders Hejlsberg http://en.wikipedia.org/wiki/Anders_Hejlsberg talk about C# and the .NET framework.  After the first 5 minutes of Anders presentation, I was lost, but was hooked on wanting to understand more. I decided then I would conquer learning OOP (yes 10 years and I’m still learning).  We’ll be learning some OOP basics, which I’m all geeked about. (Yes geeked!!)  My first assignment is due in a couple weeks, the format is straight forward.  An “Assignment” has three exercises, each exercise is 1 program.  This is where I got really excited.  I read the first assignment and said, well glad I’m in school cause I’m not sure where to begin. ๐Ÿ™‚  I wasn’t too good with story problems in school, I re-read the first assignment and said yup. Glad I’m in school.

Here is a portion of the first problem.

“A program that calculates an approximate cost to fertilize a customerโ€™s yard”  I have to collect some information, calculate this, get some more stuff, calculate more and display to the user.  Yeah ok sure. I’m confident things will work out. Just because I know the history of C# doesn’t make me any smarter on doing the homework. 

Well, I’m off but stay tuned for more stories.  It’s like a roller coaster, up, down, twist and it’s adventure!

Happy C# programming,

Steve Schofield
Microsoft MVP – IIS