2009-06-03 5 views
3

d'abord tout ce que je présente mes excuses pour mon anglais ...WCF Problème de sécurité avec UserName clientCredentialType

Puis: J'ai un problème!

J'ai écrit le code pour un simple service WCF et avec la configuration # 1 tout fonctionne très bien.

Conf # 1 - serveur

<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> 

Conf # 1 - client

<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> 

Le problème se produit lorsque je tente de définir l'authentification userName avec une classe de validation personnelle que j'ai créé. Je poste la configuration # 2.

Conf # 2 - serveur

<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> 

Conf # 2 - client

<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> 

Lorsque je démarre l'application et je reçois un

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"); 
} 

Des idées?

Merci, Alberto

+1

La partie la plus importante est manquante - le code votre validateur de connexion personnalisé - "WCFservice.Login". –

Répondre

2

Eh bien, une chose qui colle immédiatement est cet écart:

Serveur:

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

sessions fiables est activé = true.

Client:

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

sessions fiables est activé = false.

C'est sans aucun doute un décalage - surprenant, cependant, cela est le cas dans les deux votre # 1 et # 2 scénarios .....

Marc

Questions connexes