WCF 是否支持 SOAP 1.1 的 WS-Security?
我需要调用一些需要 WS-Security 的第三个 Web 服务。我使用以下配置创建了一个 WCF 端点:
<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>
问题是第 3 方服务器抛出以下异常:
收到协议 '_http://schemas.xmlsoap.org/wsdl/soap12/', 所需协议 '_http://schemas.xmlsoap.org/wsdl/soap/'。
据我了解,使用 wsHttpBinding 将导致 WCF 发送 SOAP 1.2 请求,而使用 basicHttpBinding 将导致 SOAP 1.1 请求。据我了解,由于需要 WS-Security 部分,因此我必须使用 wsHttpBinding。我的问题是如何强制执行 SOAP 1.1 请求?我有什么选择?
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:
Received protocol
'_http://schemas.xmlsoap.org/wsdl/soap12/',
required protocol
'_http://schemas.xmlsoap.org/wsdl/soap/'.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了使用 WS-Addressing (
wsHttpBinding
),但使用 SOAP 1.1(默认为 SOAP 1.2),您需要定义一个自定义 WCF 绑定(例如在配置中)并使用它:您的端点定义,使用:
当然,您可以使用其他属性扩展上面定义的自定义绑定,例如
或其他属性。有关 WCF 绑定以及如何在配置中“组合”您自己的自定义绑定的更详细、非常有用的信息,请阅读这篇优秀的 MSDN 文章 服务站:WCF 绑定深入,作者:Aaron Skonnard。
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:and then in your endpoint definition, use:
Of course, you can extend the custom binding defined above with additional properties, e.g.
<reliableMessaging>
or others.For more very detailed, very useful info on WCF bindings and how to "compose" your own custom bindings in config, read this excellent MSDN article Service Station: WCF Bindings In Depth by Aaron Skonnard.
您必须使用也支持
TransportWithMessageCredentials
(SOAP 1.1 + HTTPS + WS-Security X.509 证书令牌配置文件)的BasicHttpBinding
,或者根据您的所有需求创建自定义绑定。You must either use
BasicHttpBinding
which also supportsTransportWithMessageCredentials
(SOAP 1.1 + HTTPS + WS-Security X.509 Certificate Token profile) or create custom binding based on all your needs.