【发布时间】:2017-10-29 20:08:34
【问题描述】:
我正在尝试使用 WS-Security(签名的 Https 和消息)开发 WCF 服务,基本上 - 它正在工作,我可以使用我的 .NET 客户端应用程序使用它,但我需要能够使用 SoapUi 测试这个 web 服务.我可以生成与我的 .NET 客户端应用程序发出的几乎相同的请求,但只有一个区别 - SoapUi 使用规范化 xml-exc-c14n#,例如:
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<InclusiveNamespaces PrefixList="wsse s" xmlns="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:Transform>
还有我的 .NET 客户端:
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
我尝试过来自 Change canonicalization algorithm with WCF 改变这个, 但没有成功。我无法使用派生自 SecurityAlgorithmSuite 的类设置 defaultAlgorithmSuite 变量,因为 WCF 抛出 ArgumentOutOfRangeException 但仅在运行时。 以下是我的配置:
EndpointAddress address = new EndpointAddress(new Uri("dest_wcf_address"), EndpointIdentity.CreateDnsIdentity("cert"));
CustomBinding binding = new CustomBinding();
AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
asec.SetKeyDerivation(false);
asec.AllowInsecureTransport = true;
asec.IncludeTimestamp = true;
TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
HttpsTransportBindingElement transport = new HttpsTransportBindingElement();
transport.RequireClientCertificate = false;
binding.Elements.Add(asec);
binding.Elements.Add(textMessageEncoding);
binding.Elements.Add(transport);
config.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true, HttpsGetEnabled = true });
config.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
config.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "cert_cn");
config.Credentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindBySubjectName,
"clienct_cert_cn");
config.Credentials.ClientCertificate.Authentication.
CertificateValidationMode =
X509CertificateValidationMode.Custom;
config.Credentials.ClientCertificate.Authentication.CustomCertificateValidator = new CustomX509CertificateValidator();
config.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
ServiceEndpoint endpoint = config.AddServiceEndpoint(typeof(IService1), binding, "service_address");
endpoint.Address = address;
那么如何改变规范化算法
【问题讨论】:
标签: c# web-services wcf soapui ws-security