我目前正在探索powershell功能,但遇到了一个我无法解决的问题。任何快速提示将不胜感激 =)
我的目标:从 powershell v2.0(希望使用 new-webserviceproxy cmdlet)调用 WCF 服务(配置了 MTOM 消息编码)的方法
我的问题:当消息编码设置为 Mtom 时,new-webserviceproxy cmdlet 无法正确解析服务的响应。我收到以下错误:
电源:
$proxyObject = New-WebServiceProxy -URI "http://myserver.com/AccessService.svc?wsdl"
$proxyObject.TestWebServiceConnection()
使用“0”参数调用“TestWebServiceConnection”的异常:“客户端发现响应内容类型为 'multipart/related; type="application/xop+xml";start="<http://tempuri.org/0> ";boundary="uuid:
4001d529-32b9-4560-9f4b-550c35c67b03+id=4";start-info="text/xml"',但预期为 'text/xml'。
请求失败并显示错误消息:
- -
--uuid:4001d529-32b9-4560-9f4b-550c35c67b03+id=4
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml; charset=utf-8;type="text/xml"
<s:信封 xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
< TestWebServiceConnectionResponse xmlns="http://myserver.com/">
<TestWebServiceConnectionResult>success</TestWebServiceConnectionResult>
</TestWebServiceConnectionResponse>
</s:Body>
</s:Envelope>
--uuid:4001d529-32b9-4560-9f4b-550c35c67b03+id=4--
--。”
行: 1 char:38
+ $proxyObject.TestWebServiceConnection <<<< () >> error.txt
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
注意我可以通过其他客户端甚至微软提供的 wcfclient 工具来使用 WCF 服务。您可以看到TestWebServiceConnectionResult返回了success,但代理对象似乎无法解析响应。
行为:
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100"/>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</行为>
</服务行为>
绑定(我已经排除了超时值/阅读器配额和消息大小,因为它们的值的排列似乎与我的问题无关):
<basicHttpBinding>
<binding name="basicHttpEndpointBinding" messageEncoding="Mtom">
<security mode="None">
<transport clientCredentialType="None"/>
</security>
</basicHttpBinding>
服务
<service behaviorConfiguration="MyServiceBehavior" name="MyService.AccessService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpEndpointBinding" name="basicHttpEndpointAccessService" bindingNamespace="http://myserver.com/" contract= "MyService.IAccessService"/>
<endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="basicHttpEndpointBinding" name="mexEndpointAccess" contract="IMetadataExchange"/>
</service>