当前位置: 首页 > 编程语言 > C#

WCFoverHTTPS和签名文本共享

时间:2023-04-11 12:07:15 C#

WCFoverHTTPS和签名文本我有一个要连接的SOAP服务。它需要可通过https访问,并且需要由证书签名。我尝试了以下代码:按如下方式设置我的客户端:P4_ServiceReference.P4PortTypeClientclient=newP4_ServiceReference.P4PortTypeClient();client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode=System.ServiceModel.Security.X509CertificateValidationMode.None;client.ClientCredentials.ServiceCertificate.DefaultCertificate=newX509Certificate2(@"[..].cer");client.ClientCredentials.ClientCertificate.Certificate=newX509Certificate2(@"[..]","somepass");甚至改变了我的参考。cs在ServiceContractAttribute和OperationContractAttribute上包含ProtectionLevel=ProtectionLevel.Sign。发生的情况是wse:security标头已创建,但文字未签名。服务返回元素http://schemas.xmlsoap.org/soap/envelope/Bodymustbesigned。我缺少什么才能正确签署身体?使用此customBinding而不是basicHttpBinding来修复它。//使用HTTPS+BodySigning+Soap1.1CustomBindingbinding=newCustomBinding();设置自定义绑定//HTTPS传输HttpsTransportBindingElementtransport=newHttpsTransportBindingElement();//主体签名asec.SetKeyDerivation(false);asec.AllowInsecureTransport=true;asec.IncludeTimestamp=true;//设置SOAP11和UTF8编码TextMessageEncodingBindingElementtextMessageEncoding=newTextMessageEncodingBindingElement(MessageVersion.Soap11,Encoding.UTF8);//按顺序绑定(安全层、消息层、传输层)binding.Elements.Add(asec);binding.Elements.Add(textMessageEncoding);绑定.Elements.Add(运输);好像TransportWithMessageCredential只是将Transport用于安全并忽略所有其他内容。以上就是C#学习教程:WCFviaHTTPS并签名文分享的全部内容。如果对大家有用,需要进一步了解C#学习教程,还望大家多多关注~本文为收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:

最新推荐
猜你喜欢