c# – WCF是否支持使用SOAP 1.1的WS-Security?
发布时间:2020-12-15 03:51:06 所属栏目:百科 来源:网络整理
导读:我需要调用一些需要WS-Security的第三个Web服务.我创建了一个具有以下配置的WCF端点: system.serviceModel bindings wsHttpBinding binding name="TestBinding" security mode="TransportWithMessageCredential" message clientCredentialType="Certificate
我需要调用一些需要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> 问题是第三方服务器抛出以下异常:
我明白,使用wsHttpBinding将导致WCF发送SOAP 1.2请求,而使用basicHttpBinding会导致SOAP 1.1请求.由于WS-Security部分是必需的,据了解,我必须使用wsHttpBinding.我的问题是如何强制SOAP 1.1请求?我有什么选择? 解决方法
为了使用WS-Addressing(wsHttpBinding),但是使用SOAP 1.1(默认为SOAP 1.2),您需要定义一个自定义的WCF绑定(例如在config中),并使用它:
<bindings> <customBinding> <binding name="WsHttpSoap11" > <textMessageEncoding messageVersion="Soap11WSAddressing10" /> <httpTransport/> </binding> </customBinding> </bindings> 然后在您的端点定义中,使用: <endpoint name="WsSoap11" address="....." binding="customBinding" bindingConfiguration="wsHttpSoap11" contract="....." /> 当然,您可以使用附加属性扩展上面定义的绑定,例如< ReliableMessaging的>或其他. 有关WCF绑定的更为非常详细,非常有用的信息以及如何在配置中“编写”自己的自定义绑定,请阅读Aaron Skonnard发表的这篇优秀的MSDN文章Service Station: WCF Bindings In Depth. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |