PowerShell Tip: New-WebServiceProxy Exception
Summary
This TechNet wiki is to show the usage method of New-WebServiceProxy.
Exception
In a client environment, a few PowerShell scripts are used for querying some information using a Web Service. They faced an issue while using the script and the exception is below:
Exception calling "GetInfoByZIP" with "1" argument(s): "The operation has timed out"
At line:2 char:1 + $webservice1.GetInfoByZIP(98065).Table + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException Exeption The exception is simple and clear. 'The Operation has time out'
Troubleshooting Steps
$ws = New-WebServiceProxy -Uri 'http://www.webservicex.net/uszip.asmx?WSDL' $ws | GM |
$ws = New-WebServiceProxy -Uri 'http://www.webservicex.net/uszip.asmx?WSDL' $ws | Get-Member | ?{$_.Name -eq 'TimeOut'} |
Voila -we got it now. Check the value:
$ws = New-WebServiceProxy -Uri 'http://www.webservicex.net/uszip.asmx?WSDL' $ws.Timeout |
This is not good. The timeout value set to 1. Change it to 100000 [default].
$ws = New-WebServiceProxy -Uri 'http://www.webservicex.net/uszip.asmx?WSDL' $ws.Timeout = 100000 |
Bingo - it worked.
Enjoy PowerShell :)