我需要调用需要WS-Security的一些第三届Web服务。我创建了一个WCF端点配置如下:
I need to call some 3rd Web services that require WS-Security. I created a WCF endpoint with the following configuration:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TestBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="TestBehavior">
<callbackDebug includeExceptionDetailInFaults="true" />
<clientCredentials>
<clientCertificate findValue="Acme" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
<serviceCertificate>
<authentication certificateValidationMode="PeerOrChainTrust" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://acme.com/webservices" binding="wsHttpBinding" bindingConfiguration="TestBinding" behaviorConfiguration="TestBehavior" contract="AcmeContract" name="AcmeEndpoint"></endpoint>
</client>
</system.serviceModel>
问题是,第三方服务器中抛出以下异常:
The problem is that the 3rd party servers a throwing the following exception:
接收的协议 _http://schemas.xmlsoap.org/wsdl/soap12/, 所需的协议 。_http://schemas.xmlsoap.org/wsdl/soap/
Received protocol '_http://schemas.xmlsoap.org/wsdl/soap12/', required protocol '_http://schemas.xmlsoap.org/wsdl/soap/'.
据我所知,使用的wsHttpBinding将导致WCF发送SOAP 1.2请求,同时使用basicHttpBinding的将导致SOAP 1.1请求。由于WS-Security的部分是必需的,据我了解,我必须使用的wsHttpBinding。我的问题是我怎么强制SOAP 1.1请求?我有什么选择?
I understand that using the wsHttpBinding will cause WCF to send a SOAP 1.2 request while using the basicHttpBinding will result in a SOAP 1.1 request. Since the WS-Security parts are required, as I understand it, I have to use the wsHttpBinding. My question is how do I force a SOAP 1.1 request? What are my options?
为了使用的WS-Addressing(的wsHttpBinding
),但与SOAP 1.1(SOAP 1.2作为默认情况下),你需要定义一个自定义WCF绑定(如配置),并使用:
In order to use WS-Addressing (wsHttpBinding
), but with SOAP 1.1 (SOAP 1.2 being the default), you need to define a custom WCF binding (e.g. in config) and use that:
<bindings>
<customBinding>
<binding name="WsHttpSoap11" >
<textMessageEncoding messageVersion="Soap11WSAddressing10" />
<httpTransport/>
</binding>
</customBinding>
</bindings>
,然后在端点定义,使用:
and then in your endpoint definition, use:
<endpoint name="WsSoap11"
address="....."
binding="customBinding"
bindingConfiguration="wsHttpSoap11"
contract="....." />
当然,你可以扩展上面的自定义绑定定义的附加属性,如: &LT;可靠消息&GT;
或其他
有关的WCF绑定更非常详细,非常有用的信息,以及如何撰写你自己的自定义绑定的配置,看这个优秀的MSDN文章的