【发布时间】:2010-06-18 09:40:43
【问题描述】:
我在这里问的问题与我已经在 msdn 论坛 http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/70f40a4c-8399-4629-9bfc-146524334daf987654321@ 上问过的问题相同
我正在使用一个(很可能是基于 Java 的)Web 服务,但我完全没有修改权限。即使我会问他们也不会修改(这是一个全国性的系统)。
我已经用 WCF 编写了客户端。这是一些代码:
CustomBinding binding = new CustomBinding();
AsymmetricSecurityBindingElement element = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
element.AllowSerializedSigningTokenOnReply = true;
element.SetKeyDerivation(false);
element.IncludeTimestamp = true;
element.KeyEntropyMode = SecurityKeyEntropyMode.ClientEntropy;
element.MessageProtectionOrder = System.ServiceModel.Security.MessageProtectionOrder.SignBeforeEncrypt;
element.LocalClientSettings.IdentityVerifier = new CustomIdentityVerifier();
element.SecurityHeaderLayout = SecurityHeaderLayout.Lax;
element.IncludeTimestamp = false;
binding.Elements.Add(element);
binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
binding.Elements.Add(new HttpsTransportBindingElement());
EndpointAddress address = new EndpointAddress(new Uri("url"));
ChannelFactory<MyPortTypeChannel> factory = new ChannelFactory<MyPortTypeChannel>(binding, address);
ClientCredentials credentials = factory.Endpoint.Behaviors.Find<ClientCredentials>();
credentials.ClientCertificate.Certificate = myClientCert;
credentials.ServiceCertificate.DefaultCertificate = myServiceCert;
credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
service = factory.CreateChannel();
在此之后,对服务的每个请求都在客户端失败(我可以确认我的请求已被服务接受并且正在返回一个理智的响应)
我总是遇到以下异常
MessageSecurityException:安全性 带有 '' 的标头元素 'Timestamp' id 必须签名。
通过查看跟踪,我可以看到在响应中确实有一个时间戳元素,但在安全部分中只有一个正文的签名。
我可以让 WCF 忽略时间戳未签名的事实吗?
【问题讨论】:
标签: c# wcf wcf-client