0

WCF サービスで動作する顧客認証プロバイダーを (必死に) 取得しようとしています。これまでのところ、次のコードがあります。

web.config

      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom"  customUserNamePasswordValidatorType="MyNamespace.CustomUserNameValidator, MyNamespace" />
      </serviceCredentials>

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

      <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>

カスタム認証クラス。

public class CustomUserNameValidator : UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        // have security details been provided?
        if (null == userName || null == password)
        {
            throw new ArgumentNullException();
        }

        // authenticate user
        if (!(userName == "test" && password == "test"))
        {
            // This throws an informative fault to the client.
            throw new FaultException("SecurityFailed");
        }
    }
}

すべて正常にコンパイルされますが、ビジュアル スタジオの WCF テスト クライアントを使用して Ping というメソッド (下記) を呼び出すと、カスタム オーセンティケーターが使用されません。Ping メソッドが実行され、CustomUserNameValidator クラスにあるすべてのブレークポイントが実行されます。

これはなぜでしょうか?すべての助けに感謝します。

4

3 に答える 3

1

あなたが持っている行で

customUserNamePasswordValidatorType="MyNamespace.CustomUserNameValidator, MyNamespace"

型の 2 番目の部分 (現在は "MyNamespace" があります) は、その型を含むアセンブリの名前で、ファイル拡張子はありません。

詳細については、この質問を参照してください。

于 2010-11-09T14:43:19.443 に答える
0

ご提供いただいたすべての情報を取得し、テンプレートweb.configを作成しました。こんな感じだと思います。

<system.serviceModel>
   <services>
     <service name="<YourNameSpace>.<ServiceName>" <behaviorConfiguration="<YourNameSpace>.<BehaviorName>">
      <endpoint
        address=""
        binding="wsHttpBinding"
        bindingConfiguration="wsHttpBindingConfig"
        contract="<YourNameSpace>.<ServiceInterface>"
      />
         <!--Notice the binding is mexHttpsBinding, default is http-->
      <endpoint 
        address="mex" 
        binding="mexHttpsBinding" 
        contract="IMetadataExchange" 
      />
     </service>
   </services>
<behaviors>
   <serviceBehaviors>
       <behavior name="<YourNameSpace>.<BehaviorName>">
          <!--Notice the httpsGetEnabled, default is http-->
      <serviceMetadata httpsGetEnabled="true"/>
           <serviceDebug includeExceptionDetailInFaults="false"/>
           <serviceCredentials>
              <userNameAuthentication
                 userNamePasswordValidationMode="Custom"                 
                 customUserNamePasswordValidatorType="<YourNameSpace>.CustomUserNameValidator, <YourNameSpace>"
              />
           </serviceCredentials>
       </behavior>
   </serviceBehaviors>
</behaviors>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBindingConfig">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  <wsHttpBinding>
</bindings>

于 2010-11-10T14:49:14.350 に答える
0

いくつかの提案。

  1. WCFTestClient は最適なアプリケーションではありません。SOAPUI (www.soapUI.org でダウンロード可能) などのツールを使用することをお勧めします。WCFTestClient はすべての構成設定をインポートするわけではないため、テストに最適な方法ではありません。
  2. CustomAuthentication を使用する場合、バインディングを次のように設定します。

    <wsHttpBinding>  
        <binding name="wsHttpBindingConfig" >  
           <security mode="TransportWithMessageCredentials">  
             <message clientCredentialType="UserName" />  
           </security>  
        </binding>  
    </wsHttpBinding> 
    

将来的には、何らかの形のセキュリティが必要になると思います。マシンで自己署名 SSL 証明書を使用してテストするのは非常に簡単です。これを行う方法の詳細については、こちらを参照してください。

于 2010-11-09T02:55:42.180 に答える