MEA Center of Expertise

We are a 120+ technology enthusiasts helping Microsoft customers around Middle-East & Africa region. We bridge Microsoft tools & technologies to their businesses.

How To: Access XML WebService using Windows PowerShell

How To: Access XML WebService using Windows PowerShell

  • Comments 1
  • Likes

In the next few lines I'll show you how to access any XML WebService in a few seconds using Windows PowerShell.

Windows PowerShell has a cmdlet called "New-WebServiceProxy". This cmdlet create a WebService proxy object that connects to the WebService and allow you to use and access it.

Example:

In this example I'll use a free WebService called "GeoIPService". GeoIPService allows you to determine the country of an IP Address.

WebService URI: http://www.webservicex.net/geoipservice.asmx?WSDL

Web Method:

  • GetGeoIP(string IPAddress); //Get GeoInfo for a specific IP Address
  • GetGeoIPContext(); //Get GeoInfo for your IP Address

PowerShell Code:

Method #1 - GetGeoIP:  

$GeoIPWebService = New-WebServiceProxy -Uri "http://www.webservicex.net/geoipservice.asmx?WSDL"
$GeoIPWebService.GetGeoIP("213.131.66.246");

Method #2 - GetGeoIPContext:  

(New-WebServiceProxy -Uri "http://www.webservicex.net/geoipservice.asmx?WSDL").GetGeoIPContext() 

For more info and examples, use the following command:

Get-Help New-WebServiceProxy -Detailed


 

Comments
  • Don't you get some errors for the GetGeoIP function? The other one is fine, but here I get "System.ArgumentNullException: Value cannot be null. Parameter name: input at System.Text.RegularExpressions.Regex.IsMatch(String input) at WebserviceX.Service.Adapter.IPAdapter.CheckIP(String IP) at WebserviceX.Service.GeoIPService.GetGeoIP(String IPAddress)"

    Any ideas?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment