This post will introduce you to webservices and how you can interact with them using PowerShell. But first: What is a web service? The term describes a standarized way of integrating Web-based applications using the open standards (XML, SOAP, WSDL and UDDI) over an Internet protocol network.
First, we need a Webservice to start to illustrate how to work with PowerShell. We’ll use a simple calculator web services running on this website http://www.dneonline.com/calculator.asmx.
If you go to the above website you’ll see a list of math operations available to use. As you can see bellow, there are 4 methods listed:
We’ll start with the Add method, then open PowerShell and start typing the following:
Second, invoke the command
Where we’re going to name the class in a way that allows us to identify the webservice. For the example we simply use “namespace”.
Then we can execute the following command to identify the available methods of the webservice:
In our case, we can take Add, where the output of the previous command indicates the following:
That gives us a clue of how to consume it… To make a sum I invoke the
Add method as follows:
Obtaining the result of the operation:
This is an easy way to consume a webservice using PowerShell.