2009-06-03 16 views
3

まず、私は自分の英語のために謝罪します...UserName clientCredentialTypeを使用したWCFセキュリティ問題

次に:問題があります。

私はシンプルなWCFサービスのコードを書いており、設定#1はすべてうまくいきます。

コンファレンス#1 - サーバー

<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="WCFservice.Service" 
       behaviorConfiguration="WCFservice.ServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress = "http://localhost:8731/WCFservice/" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="" binding="wsHttpBinding" contract="WCFservice.IService"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSCertificateSecurity"> 
      <reliableSession enabled="true"/> 
      <security mode="Message"> 
      <message clientCredentialType="UserName"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFservice.ServiceBehavior"> 
      <serviceCredentials> 
      <serviceCertificate findValue="cn=abc" 
        storeLocation="LocalMachine" storeName="TrustedPeople" 
        x509FindType="FindBySubjectDistinguishedName"/> 
      <clientCertificate> 
       <authentication certificateValidationMode="PeerTrust"/> 
      </clientCertificate> 
      </serviceCredentials> 
      <serviceMetadata httpGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="True" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

コンファレンス#1 - 私は私が作成した個人的なバリデーションクラスにユーザ名認証を設定しようとすると、クライアント

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IService"> 
      <reliableSession enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" 
         proxyCredentialType="None" realm="" /> 
      <message clientCredentialType="Windows" 
        negotiateServiceCredential="true" 
        establishSecurityContext="true" 
        algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8731/WCFservice/" 
       binding="wsHttpBinding" 
       bindingConfiguration="WSHttpBinding_IService" 
       contract="WCF.IService" 
       name="WSHttpBinding_IService"> 
     <identity> 
      <userPrincipalName value="myname" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 

問題が発生します。私は設定#2を投稿する。

コンファレンス#2 - サーバー

<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="WCFservice.Service" 
       behaviorConfiguration="WCFservice.ServiceBehavior"> 
     <host> 
      <baseAddresses> 
      <add baseAddress = "http://localhost:8731/WCFservice/" /> 
      </baseAddresses> 
     </host> 
     <endpoint address="" binding="wsHttpBinding" contract="WCFservice.IService"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSCertificateSecurity"> 
      <reliableSession enabled="true"/> 
      <security mode="Message"> 
      <message clientCredentialType="UserName"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFservice.ServiceBehavior"> 
      <serviceCredentials> 
      <userNameAuthentication 
       userNamePasswordValidationMode="Custom" 
       customUserNamePasswordValidatorType="WCFservice.Login, WCFservice"/> 
      <serviceCertificate findValue="cn=abc" 
       storeLocation="LocalMachine" storeName="TrustedPeople" 
       x509FindType="FindBySubjectDistinguishedName"/> 
      <clientCertificate> 
       <authentication certificateValidationMode="PeerTrust"/> 
      </clientCertificate> 
      </serviceCredentials> 
      <serviceMetadata httpGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="True" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

コンファレンス#2 - クライアント

<configuration> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_IService"> 
      <reliableSession enabled="false" /> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" 
        proxyCredentialType="None" realm="" /> 
      <message 
        clientCredentialType="UserName" 
        negotiateServiceCredential="true" 
        establishSecurityContext="true" 
        algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:8731/WCFservice/" binding="wsHttpBinding" 
     bindingConfiguration="WSHttpBinding_IService" contract="WCF.IService" 
     name="WSHttpBinding_IService"> 
     <identity> 
      <userPrincipalName value="myname" /> 
     </identity> 
     </endpoint> 
    </client> 

私は、アプリケーションを起動し、私は

System.ServiceModel.Security.SecurityNegotiationException

を取得すると
private void button1_Click(object sender, EventArgs e) 
{ 
    WCF.XnottaLightServiceClient client = new WCF.XnottaLightServiceClient(); 
    client.ClientCredentials.UserName.UserName = "user"; 
    client.ClientCredentials.UserName.Password = "pass"; 

    string[] s = textBox6.Text.Split('§'); 
    int[] i = new int[s.Length]; 
    for(int j = 0; j < i.Length; j++) 
    { 
     i[j] = Convert.ToInt32(s[j]); 
    } 

    string string1 = client.getString("xnl"); 
} 

アイデア?

おかげで、アルベルト・

+1

最も重要な部分が欠落している - のコードをあなたのカスタムログインバリデーター - "WCFservice.Login"。 –

答えて

2

まあ、すぐに突き出て一つのことは、この矛盾です:

サーバー:

<wsHttpBinding> 
     <binding name="WSCertificateSecurity"> 
      <reliableSession enabled="true"/> 

信頼性の高いセッションをtrue =有効になっています。

クライアント:

<wsHttpBinding> 
     <binding name="WSHttpBinding_IService"> 
      <reliableSession enabled="false" /> 

信頼性の高いセッションが= falseを有効になります。

これは間違いなく不一致である - 驚くべきことに、しかし、これは、両方のあなたの#1、#2のシナリオである場合.....

マルク・

関連する問題