我正在尝试使用带有证书的消息安全性在 WCF 中创建测试服务/客户端。我正在使用 Visual Studio 开箱即用创建的基本服务,并从我设置为客户端的另一个项目中调用它。
我创建了两个证书,一个用于服务器,另一个用于客户端,并将它们导入到我的证书存储中。我还按照以下说明操作:http: //msdn.microsoft.com/en-us/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>
我的客户端配置是:
<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">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Certificate" negotiateServiceCredential="false"
algorithmSuite="Default" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1704/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
name="WSHttpBinding_IService1" behaviorConfiguration="endpointCredentialBehaviours">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="endpointCredentialBehaviours">
<clientCredentials>
<clientCertificate findValue="WCFClient" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
我在客户端调用服务:
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
string s = client.GetData(1);
label1.Text = s;
client.Close();
谁能告诉我我做错了什么?