Getting Started with SOAP-Based Web Services and PowerShell

PowerShell's Invoke-WebRequest handles SOAP wonderfully

Mark Minasi

December 21, 2015

4 Min Read
Getting Started with SOAP-Based Web Services and PowerShell

This month, I'll continue my how-to series about using PowerShell's Invoke-WebRequest cmdlet to query online Web services by moving from the newer RESTful-type Web services to the older (but still extant) SOAP-type Web services. The housing market is slowly recovering in the United States, so you might appreciate having easy access to payment information via a Web service that I'll introduce this month!

Let's query a free public SOAP service hosted (and well documented, thankfully) by www.webservice.net. Its Mortgage Web Service (MWS) accepts a loan period in years, interest rate in percent, total house loan amount, and annual taxes and insurance. It then grinds the numbers and returns the total projected monthly payment.

Take a look at MWS's home page, and find the Endpoint heading. Under that is MWS's URI:

http://www.webservicex.net/mortgage.asmx?WSDL

Notice two things. First, the URI has an .asmx extension. That's almost always the extension of a SOAP URI. Second, notice the query string ?WDSL. That is a reference to some XML that allows this Web service to describe itself and its required inputs to the outside world, and what it will provide in return. (That will be important next month, when I use something called a "Web service proxy" to simplify calling this service.)

Below the URI, you'll see GetMortgagePayment. That's the name of the "method" in this Web service. MWS has only one method, but you'll run into many more Web services that have more than one method. Click GetMortgagePayment to reveal an area with the title SOAP 1.1. This area shows how to create an XML file that feeds MWS the inputs that it needs, with the inputs entered as elements in the XML.

The text in that figure is the entirety of the SOAP text that MWS needs, but you needn't put all that in your file, as PowerShell automatically inserts everything up to and including the SOAPAction… line.

To build the SOAP XML file, copy everything from <?xml... onward, as seen here, into Notepad:

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like