在为我公司购买的产品使用网络服务时遇到一个奇怪的问题。该产品称为Campaign Commander,由一家名为Email Vision的公司生产。我们正在尝试使用“数据批量更新SOAP API”。
每当我尝试调用Web服务上的任何方法时,调用实际上都会成功,但是客户端在处理响应时会失败,并且会出现异常。
错误的详细信息如下,感谢您提供的任何帮助。
使用Web引用时出错(旧式Web服务客户端)
当将该服务用作Web引用时,对于我进行的任何调用,我都会获得InvalidOperationException
,并显示以下消息:
Client found response content type of 'multipart/related; type="application/xop+xml"; boundary="uuid:170e63fa-183c-4b18-9364-c62ca545a6e0"; start="<root.message@cxf.apache.org>"; start-info="text/xml"', but expected 'text/xml'.
The request failed with the error message:
--
--uuid:170e63fa-183c-4b18-9364-c62ca545a6e0
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/">
<return>DpKTe-9swUeOsxhHH9t-uLPeLyg-aa2xk3-aKe9oJ5S9Yymrnuf1FxYnzpaFojsQSkSCbJsZmrZ_d3v2-7Hj</return>
</ns2:openApiConnectionResponse>
</soap:Body>
</soap:Envelope>
--uuid:170e63fa-183c-4b18-9364-c62ca545a6e0--
--.
如您所见,响应消息信封看起来有效(这是有效响应,并且调用成功),但是客户端似乎内容类型存在问题,并生成异常。
使用服务引用时出错(WCF客户端)
当我将该服务作为服务引用使用时,对于我进行的任何调用,我都会获得
ProtocolException
,并显示以下消息:The content type multipart/related; type="application/xop+xml"; boundary="uuid:af66440a-012e-4444-8814-895c843de5ec"; start="<root.message@cxf.apache.org>"; start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 648 bytes of the response were: '
--uuid:af66440a-012e-4444-8814-895c843de5ec
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/">
<return>Dqaqb-MJ9V_eplZ8fPh4tdHUbxM-ZtuZsDG6GalAGZSfSzyxgtuuIxZc3aSsnhI4b0SCbJsZmrZ_d3v2-7G8</return>
</ns2:openApiConnectionResponse>
</soap:Body>
</soap:Envelope>
--uuid:af66440a-012e-4444-8814-895c843de5ec--'.
就像前面的例子一样;我们有一个有效的Soap响应,并且调用成功,但是客户端似乎内容类型有问题,并生成了异常。
我可以设置任何选项以使客户端的响应类型没有问题吗?我已经做了一些Google搜索,但到目前为止,没有发现对我有帮助。
最佳答案
对于任何遭受同样问题困扰的人;我已经找到了将Web服务用作服务引用(WCF)的解决方案。 BasicHttpBinding.MessageEncoding属性需要设置为“Mtom”。
这是必需的配置设置的片段:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding messageEncoding="Mtom">
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
编辑:如果您在使用自定义绑定(bind)时遇到相同的问题,请引用answer from @robmzd。
我仍然没有找到将其用作旧式Web引用的解决方案。
关于c# - 消耗网络服务时出错,内容类型 “application/xop+xml”与预期的 “text/xml”类型不匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10496186/