0

メッセージセキュリティモードを有効にしてwcfサービスを作成しましたこれは私のサービスです

    [ServiceContract]
    public interface IMessagingServices
    {
        [OperationContract]
        string SendMessage(string from, string to, string message);

        [OperationContract]
        List<Message> GetMessages(string from, string to);

        [OperationContract]
        int DeleteMessages(int[] idList);
    }
}

これが設定です

<bindings>
      <wsHttpBinding>
        <binding name="wsBinding1">
          <security mode="Message">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>



<services>


  <service name="MessagingServices" behaviorConfiguration="SecureServiceBehavior" >
    <endpoint address="" binding="wsHttpBinding" contract="IMessagingServices" bindingConfiguration="wsBinding1" />
    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetaDataExchange"/>-->
  </service>

</services>


<behaviors>

  <endpointBehaviors>
    <behavior name="httpBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>

    <behavior name="SecureServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceCredentials>
        <serviceCertificate findValue="KServic.local" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="AuthenticationHandler, mynamespace" />
      </serviceCredentials>
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

すべてが正常なようです。VS2010のサービス参照の追加でサービスを追加でき、プロキシが連続して作成されますが、クライアントでサービスオペレーションを呼び出そうとすると、エラーが発生します。これはクライアントコードです。

ServiceReference1.MessagingServicesClient mscClient = new MessagingServicesClient();

           // mscClient.Open();

            mscClient.ClientCredentials.UserName.UserName = "test";
            mscClient.ClientCredentials.UserName.Password = "test";
            mscClient.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByIssuerName, "KService.local");

             // error is here
            var msg = mscClient.SendMessage("rnd.test", "rnd.test", "Hello brother!");

            mscClient.Close();

これはエラーです

送信メッセージのIDチェックに失敗しました。期待されるIDは'identity(http://schemas.xmlsoap.org/ws/2005/05/identity/right/possessproperty:http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint)'「http://192.168.100.24:16027/MessagingServices.svc」ターゲットエンドポイントの場合。

ここで何が問題になっていますか?どうすればこの問題を解決できますか?

4

1 に答える 1

0

メッセージ セキュリティを使用する場合は、クライアント側でエンドポイント IDを設定する必要があります。
あなたが提供したコードは、エンドポイント ID ではなく、クライアント資格情報を設定します。

.config ファイルを介して ID を設定する場合は、WCF 構成スキーマの<identity>および要素を参照してください。コードで ID を設定する場合は、クラスを参照してください。<certificateReference>X509CertificateEndpointIdentity

var certificate = ...; // load X509Certificate2 instance from the X509Store
var address = new EndpointAddress(uri, new X509CertificateEndpointIdentity(certificate));

サービス証明書は、クライアント側で使用する前に検証する必要があることに注意してください。詳細については、<authentication> of <serviceCertificate>エレメント ページを参照してください。

于 2012-09-10T06:56:29.423 に答える