メッセージ セキュリティと証明書を使用して、WCF でテスト サービス/クライアントを作成しようとしています。Visual Studio がすぐに作成できる基本的なサービスを使用しており、クライアントとして設定した別のプロジェクトから呼び出しています。
サーバー用とクライアント用の 2 つの証明書を作成し、証明書ストアにインポートしました。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();
誰が私が間違っているのか教えてもらえますか?