在将 WCF 服务配置为使用 WS-Addressing 规范的 2004 年 8 月版时,Windows Communication Foundation (WCF) 服务与 Web Services Enhancements 3.0 for Microsoft .NET 客户端具有网络级别兼容性。
使 WCF 服务与 WSE 3.0 客户端进行互操作
定义 WCF 服务的自定义绑定。
若要指定将 WS-Addressing 规范的 2004 年 8 月版用于消息编码,必须创建自定义绑定。
将子级 customBinding Element添加到服务的配置文件的 <Bindings>。
通过将 binding element添加到 customBinding Element中并设置 name 属性,为绑定指定一个名称。
通过将子级 Security element添加到 binding element中,指定身份验证模式和用于保护消息安全的 WS-Security 规范的版本,该版本与 WSE 3.0 兼容。
若要设置身份验证模式,请设置 Security element的 authenicationMode 属性。身份验证模式大致等效于 WSE 3.0 中的关守安全断言。下表将 WCF 中的身份验证模式映射为 WSE 3.0 中的关守安全断言。
WCF 身份验证模式 WSE 3.0 关守安全断言 anonymousForCertificateSecurity
kerberosSecurity
mutualCertificate10Security*
MutualCertificate
mutualCertificate11Security*
usernameOverTransportSecurity
usernameForCertificateSecurity
*mutualCertificate10Security 和 mutualCertificate11Security 关守安全断言之间的主要区别在于,WSE 用于保护 SOAP 消息的 WS-Security 规范的版本不同。mutualCertificate10Security 使用 WS-Security 1.0,而 WS-Security 1.1 用于 mutualCertificate11Security。对于 WCF,WS-Security 规范的版本在 Security element的 messageSecurityVersion 属性中指定。
若要设置用于保证 SOAP 消息安全的 WS-Security 规范的版本,请设置 Security element的 messageSecurityVersion 属性。若要与 WSE 3.0 进行互操作,请将 messageSecurityVersion 属性的值设置为 WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10。
通过添加 textMessageEncoding element并将 messageVersion 设置为它的 Soap11WSAddressingAugust2004 的值,指定 WCF 使用 WS-Addressing 规范的 2004 年 8 月版本。
注意:
在使用 SOAP 1.2 时,请将 messageVersion 属性设置为 Soap12WSAddressingAugust2004。
指定该服务使用自定义绑定。
将Service Endpoint元素的 binding 属性设置为 customBinding。
将Service Endpoint元素的 bindingConfiguration 属性设置为在 binding element的 name 属性中为自定义绑定指定的值。
示例
下面的代码示例指定 Service.HelloWorldService
使用自定义绑定与 WSE 3.0 客户端进行互操作。自定义绑定指定使用 WS-Addressing 的 2004 年 8 月版本和 WS-Security 1.1 规范集对所交换的消息进行编码。使用 AnonymousForCertificate 身份验证模式保证消息的安全。
<configuration>
<system.serviceModel>
<services>
<service
behaviorConfiguration="ServiceBehavior"
name="Service.HelloWorldService">
<endpoint binding="customBinding" address=""
bindingConfiguration="ServiceBinding"
contract="Service.IHelloWorld"></endpoint>
</service>
</services>
<bindings>
<customBinding>
<binding name="ServiceBinding">
<security authenticationMode="AnonymousForCertificate"
messageProtectionOrder="SignBeforeEncrypt"
messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
requireDerivedKeys="false">
</security>
<textMessageEncoding messageVersion ="Soap11WSAddressingAugust2004"></textMessageEncoding>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<behaviors>
<behavior name="ServiceBehavior" returnUnknownExceptionsAsFaults="true">
<serviceCredentials>
<serviceCertificate findValue="CN=WCFQuickstartServer" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName"/>
</serviceCredentials>
</behavior>
</behaviors>
</system.serviceModel>
</configuration>