我正在尝试使用Message Security和证书在WCF中创建测试服务/客户端。我正在使用Visual Studio开箱即用创建的基本服务,并从我已设置为客户端的另一个项目中调用它。
我创建了两个证书,一个用于服务器,另一个用于客户端,并将它们导入到我的证书存储中。我还按照以下说明进行了操作:http : //msdn.microsoft.com/zh-cn/library/ms733098.aspx
但是,没有运气。从客户端调用服务器时,出现错误:
没有为目标'http:// localhost:1704 / Service1.svc'提供服务证书。在ClientCredentials中指定服务证书。
我的服务配置如下:
<system.serviceModel>
<services>
<service name="WcfService2.Service1" behaviorConfiguration="ServiceCredentialsBehavior">
<endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1" bindingConfiguration="MyHTTPBindingConfig">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="MyHTTPBindingConfig">
<security mode="Message">
<message clientCredentialType="Certificate" negotiateServiceCredential="false" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceCredentialsBehavior">
<serviceCredentials>
<serviceCertificate findValue="WCFTest" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我的客户端配置是:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false"> …
Run Code Online (Sandbox Code Playgroud) 我正在使用WCF客户端与非WCF Web服务进行通信.
此Web服务要求SOAP消息的主体已签名,但是,我无法生成有效的SOAP请求.
我已经实现了一个继承自IClientMessageInspector的ClientMessageInspector,我在其中修改了BeforeSendRequest方法中的消息以添加XML数字签名.我使用SignedXML类来执行此操作.
我正在使用用于WSDL和SOAP的IBM Web服务验证工具来检查我的数字签名是否经过验证.
我的问题是,当我在Reference URI中指定一个完整的命名空间引用时,我正在使用的IBM工具说我有一个有效的签名.从XML数字签名规范,我应该能够引用属性,没有命名空间,但是,当我这样做时,我没有得到有效的数字签名.
这是我正在生成的SOAP请求,我的工具说它具有有效的签名,但Web服务不喜欢它:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapsec="http://schemas.xmlsoap.org/soap/security/2000-12"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header>
<soapsec:Signature>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
<Reference URI="http://schemas.xmlsoap.org/soap/security/2000-12#Body">
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<DigestValue>4mt5wluUTu5tpR2d5UemVSLvqTs=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>UZ7HzfE3GxIY9hg...</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>MIIEkTCCA3mgAwIBAgIQCu...</X509Certificate>
</X509Data>
<KeyValue>
<RSAKeyValue>
<Modulus>0C3e9HDx5Yq6FLUxIgjJ...</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
</soapsec:Signature>
</s:Header>
<s:Body soapsec:id="Body">
.... SOAP Body Here ...
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
这是我想要生成的SOAP请求,但我的工具说这有一个无效的签名,Web服务也告诉我签名无效:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:s="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapsec="http://schemas.xmlsoap.org/soap/security/2000-12"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header>
<soapsec:Signature>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod …
Run Code Online (Sandbox Code Playgroud)