我试图配置我的WCF客户端来创建包含WS-Addressing,WS-Security和TLS的SOAP 1.1请求。如何配置WCF只签署TimeStamp报头
安全要求是消息包含用户名令牌TimeStamp并且TimeStamp使用包含的BinarySecurityToken进行签名。
我已经使用下面link的示例来创建我的WCF客户端绑定。我略微修改了该示例(请参见下文),以便HTTPS用作传输机制,而MessageSecurity基于UsernameOverTransport。
HttpsTransportBindingElement httpsTransport = new HttpsTransportBindingElement();
// the message security binding element will be configured to require 2 tokens:
// 1) A username-password encrypted with the service token
// 2) A client certificate used to sign the message
// Instantiate a binding element that will require the username/password token in the message (encrypted with the server cert)
TransportSecurityBindingElement messageSecurity = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
// Create supporting token parameters for the client X509 certificate.
X509SecurityTokenParameters clientX509SupportingTokenParameters = new X509SecurityTokenParameters();
// Specify that the supporting token is passed in message send by the client to the service
clientX509SupportingTokenParameters.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;
// Turn off derived keys
clientX509SupportingTokenParameters.RequireDerivedKeys = false;
// Augment the binding element to require the client's X509 certificate as an endorsing token in the message
messageSecurity.EndpointSupportingTokenParameters.Endorsing.Add(clientX509SupportingTokenParameters);
// Create a CustomBinding based on the constructed security binding element.
return new CustomBinding(messageSecurity, httpsTransport);
由该客户端产生的SOAP消息非常接近达到我打电话的服务的要求,唯一的问题是,WSA:要地址已经被签署,以及时间戳地址。
有没有一种方法可以确切指定哪些WCF标头被签名?由于我需要限制客户端只签署TimeStamp标头。
我不能使用ProtectionLevel设置,因为我试图签署TimeStamp,它是以下链接中提到的基础设施数据的内容http://msdn.microsoft .com/en-us/library/aa347692.aspx#Y1432。我该如何得到 – Edward 2011-05-09 21:10:54
请查看答案中的IClientMessageInspector链接。它显示了如何在发送到服务之前修改soap消息。您可以访问BeforeSendRequest方法中的所有soap头文件。你只需要弄清楚如何数字签署wsa:To header项目并覆盖肥皂信息中的现有项目(尽管这可能是困难的部分)。 – 2011-05-09 21:17:58
我遇到的问题是WCF绑定同时签署了wsa:To和wsu:TimeStamp,当我要求只签署wsu:TimeStamp时。 我可以手动操作消息来替换现有的签名,但我想尽量减少我们在SOAP消息上执行的自定义操作的数量。 我已经设法通过将messageVersion指定为Soap11而不是Soap11WSAddressing10,然后手动添加WS-Addresing头来避免需要手动实现签名机制。 – Edward 2011-05-09 22:00:24