我已使用VS2010中的“添加服务引用”对话框成功添加了服务引用。但是,当我尝试访问所述Web服务方法时,我收到以下ProtocolException:
Test method Test.Entities.DocumentumServiceClient_Tests.Can_Read_Client_Message threw
exception: System.ServiceModel.ProtocolException: The content type multipart/related;
type="application/xop+xml"; boundary="uuid:976dd31d-c531-4298-b12c-e799c8eb4bed";
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 919 bytes of the response were: <code>
'--uuid:976dd31d-c531-4298-b12c-e799c8eb4bed
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>
<ns8:getRepositoryNameResponse
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dfs-dm-core-profiles="http://irrelevant.com/"
xmlns:dfs-dm-core-context="http://irrelevant2.com/"
xmlns:dfs-dm-core-properties="http://irrelevant3.com/"
xmlns:dfs-dm-core-content="irrelevant4.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns8="http://irrelevant5.com/">
<return>to the Dagobah system</return>
</ns8:getRepositoryNameResponse>
</soap:Body>
</soap:Envelope>
--uuid:976dd31d-c531-4298-b12c-e799c8eb4bed--'.
在广泛的谷歌搜索之后,这似乎是服务器上的SOAP 1.2和我的项目中的SOAP 1.1之间的不匹配。我显然应该使用WSHttpBinding而不是BasicHttpBinding。以下是app.config生成的相关部分:
<system.serviceModel>
<client>
<endpoint address="http://irrelevant.com/Service"
binding="basicHttpBinding"
bindingConfiguration="CMSPersistantManagerServiceServiceSoapBinding"
contract="DocumentumService.CMSPersistentManagerService"
name="CMSPersistentManagerServicePort" />
</client>
<bindings>
<basicHttpBinding>
<binding name="DfsAgentService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1000000" maxBufferPoolSize="10000000" maxReceivedMessageSize="1000000"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="DfsContextRegistryService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1000000" maxBufferPoolSize="10000000" maxReceivedMessageSize="1000000"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="DfsDefaultService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1000000" maxBufferPoolSize="10000000" maxReceivedMessageSize="1000000"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="CMSPersistantManagerServiceServiceSoapBinding"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
我应该做些什么来告诉服务引用对话框使用WSHttpBinding生成1.2版本?这是WSDL的错吗?任何帮助都将受到赞赏,因为我在google-rope的最后。
答案 0 :(得分:2)
我遇到了与我无法控制的第三方SOAP Web服务类似的问题,我发现我必须使用SOAP 1.2,而不是Visual Studio使用BasicHttpBinding添加的默认SOAP 1.1标头。
我使用的服务与WSHttpBinding的安全功能不兼容,因此通过创建自定义绑定,您可以使用BasicHttpBinding来使用SOAP 1.2,但是修改.config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="httpSoap12">
<textMessageEncoding messageVersion="Soap12"/>
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://server.com/interface/SoapService.asmx"
binding="customBinding" bindingConfiguration="httpSoap12"
contract="Service.ThingsYouNeed" name="ThingsYouNeed" />
</client>
</system.serviceModel>
在Visual Studio 2010中添加服务引用后,对配置进行这些修改。
希望这有帮助。