5

メッセージ セキュリティと証明書を使用して、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();

誰が私が間違っているのか教えてもらえますか?

4

4 に答える 4

4

これは、動作するクライアント構成の例です。

<client>
 <endpoint address="http://example.com/Myservice.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
        contract="Core.IService" name="WSHttpBinding_IService" behaviorConfiguration="myServiceBehaviour" >
   <identity>
    <dns value="SampleServiceCertificate"/>
   </identity>
 </endpoint>
</client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="myServiceBehaviour">
          <clientCredentials>
            <serviceCertificate>
              <defaultCertificate storeLocation="LocalMachine" storeName="My" findValue="SampleServiceCertificate" x509FindType="FindBySubjectName"  />
            </serviceCertificate>
          </clientCredentials>
        </behavior>        
      </endpointBehaviors>      
    </behaviors>

投稿された構成では、clientCredentials ノードに serviceCertificate 子ノードがありません。

于 2015-02-19T14:39:35.330 に答える
2

エラーが示すように、クライアントが証明書を提供していないようです。これをトラブルシューティングするために私が行う最初のステップは、クライアント証明書が必要な場所にあり、構成ファイルの名前が正しいことを確認することです。MMCでそれを行うことができます。これを行う方法の説明は次のとおりです。

方法: MMC スナップインで証明書を表示する: http://msdn.microsoft.com/en-us/library/ms788967.aspx

また、コードを使用して手動でクライアント証明書を追加してみます。

方法: クライアント資格情報の値を指定する: http://msdn.microsoft.com/en-us/library/ms732391.aspx

于 2012-04-16T03:01:52.223 に答える
0

で証明書を提供する必要がありますclient.Credentials。詳細については、このリソースに従ってください。

于 2012-04-16T19:03:01.167 に答える