从PowerShell中调用Web服务:“服务器无法识别HTTP Header SOAPAction的值”
问题描述:
我正尝试从PowerShell脚本调用Web服务。从PowerShell中调用Web服务:“服务器无法识别HTTP Header SOAPAction的值”
我不是Web服务的作者,也不了解更多关于Web服务的知识。 (我只是在PowerShell中也是如此。)
Web软件的供应商为我提供了一个.wsdl文件。我对其运行了wsdl.exe,然后针对生成的.cs文件运行了csc.exe,以生成代理.dll文件。
在我的PowerShell脚本,我实例化对象,并设置其url属性并试图调用的方法之一:
[Reflection.Assembly]::LoadFrom("$ProxyDllPath\VendorProxy.dll")
$myVar = new-object VendorObject
$myVar.url = "http://servername/serverdirectory/serverfile.asmx"
$myStuff = $myVar.GetStuff()
当我执行,我得到异常:
Exception calling "GetStuff" with "0" argument(s): "Server did not recognize the value of HTTP Header SOAPAction: ."
At C:\users\xxx\desktop\xxx.ps1:56 char:55
+ $myStuff = $myVar.GetStuff<<<<()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
我把我的电话的网络捕获,然后看一看:
POST /serverdirectory/serverfile.asmx HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.4927)
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Authorization: NTLM TlRMTVNTUAABAAAAt4II4gAAAAAAAAAAAAAAAAAAAAAGAbAdAAAADw==
Host: servername
Content-Length: 0
的WSDL DESCRIPTIO n对于这个web服务是:
<wsdl:operation name="GetStuff">
<soap:operation soapAction="" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
恐怕我并不真正了解这个例外;正如我所说的,网络服务不是我要求胜任的领域。
如何确定服务器需要的soap动作,以及如何配置我的$ myVar以使用该soap动作?
答
通常,“soapAction”将具有名称空间限定的方法名称(如“http://tempuri.org/GetStuff”)。您可能需要检查您的asmx服务。
如果您正在运行PowerShell V2(如果可以的话,您应该这样做),您可以尝试使用New-WebServiceProxy构建代理。
$MyProxy = New-WebServiceProxy -Uri 'http://servername/serverdirectory/serverfile.asmx' -Namespace 'MyService'