Calling a Web Service

I created a webservice on my local machine and connect to it with localhost. The webservice works great when I access it via IE and I am able to do all the functions created with no problem. When I create a script to access the webservice via powershell I get the following error. If I access an outside webservice like get teh weather powershell works just fine.
(b)My Script(/b)

$proxy2 = New-WebServiceProxy -Uri ‘http://localhost/API/webservice.asmx?WSDL
[xml]$Response = $proxy2.GetStatus()
$Response.Status | Format-List

(b)Powershell’s Response(/b)
PS C:\Windows\system32> $proxy2 = New-WebServiceProxy -Uri ‘http://localhost/API/webservice.asmx?WSDL

[xml]$Response = $proxy2.GetStatus()
$Response.Status | Format-List
Exception calling “GetStatus” with “0” argument(s): "The request failed with the error message:

Object moved
Object moved to here.

At line:3 char:1

  • [xml]$Response = $proxy2.GetStatus()
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : WebException

PS C:\Windows\system32>

I have done an extensive search to try to shed some light on what the issue is and have not come up with anything usable

Any help you can give is greatly appreciated.



It doesn’t seem anyone has any ideas on this one… But it’s possible the browser is doing something you aren’t seeing. Have you used something like Fiddler to see what the exact browser activity is?

Your web server seems to be configured strangely. If you look at the URL of the “Object moved HERE” text, you see it is trying to redirect you to API/webservice.asmx?AspxAutoDetectCookieSupport=1. That seems strange, since a web service shouldn’t need cookies, unless your service needs them. IE probably handles this because its a full-blown browser with cookie support. I would guess Invoke-WebRequest doesn’t work that way.