2011-10-05 3 views
4

J'essaie de créer un service wcf qui effectue une authentification de base, mais j'ai des problèmes.Service WCF utilisant le transport clientCredentialType Basic

Voici ce que mon web.config pour le service ressemble à:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <client /> 
     <services> 
      <service name="Service.DataExchangeService" behaviorConfiguration="MyBehavior"> 
       <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsDataImportEndpoint" contract="Service.IDataExchangeService"> 
        <identity> 
         <dns value="localhost" /> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
       <host> 
        <baseAddresses> 
         <add baseAddress="http://localhost:8732/Design_Time_Addresses/DataExchange.Server.Service/Service1/" /> 
        </baseAddresses> 
       </host> 
      </service> 
     </services> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="wsDataImportEndpoint" maxBufferPoolSize="2147483647" 
        maxReceivedMessageSize="2147483647"> 
        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
         maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <security mode="Transport"> 
         <transport clientCredentialType="Basic"/> 
         <message clientCredentialType="UserName" negotiateServiceCredential="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="MyBehavior"> 
        <serviceMetadata httpsGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 
        <serviceCredentials> 
         <userNameAuthentication customUserNamePasswordValidatorType="DataExchange.Server.Service.UserNameValidator, DataExchange.Server.Service" 
               userNamePasswordValidationMode="Custom" /> 
        </serviceCredentials> 
       </behavior> 
       <behavior name=""> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
    </system.serviceModel> 
    <connectionStrings> 
     <add name="ApplicationServices" connectionString="data source=sharept07\mssqlserver2008;initial catalog=VOS.Membership;integrated security=True;" providerName="System.Data.SqlClient" /> 
     <add name="ROSEntities" connectionString="metadata=res://*/ROSModel.csdl|res://*/ROSModel.ssdl|res://*/ROSModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=sharept07\MSSQLServer2008;initial catalog=VOS;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
</configuration> 

et voici ce que mon fichier de configuration de client ressemble à:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="WSHttpBinding_IDataExchangeService" 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="2147483647" 
        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="Transport"> 
         <transport clientCredentialType="Basic" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="UserName" negotiateServiceCredential="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="https://server.com:446/DataExchangeService/DataExchangeService.svc" 
       binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataExchangeService" 
       contract="DataExchangeSvc.IDataExchangeService" name="WSHttpBinding_IDataExchangeService"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

et voici comment j'appelle le service dans mon client:

static void Main(string[] args) 
    { 
     using (var client = new DataExchangeSvc.DataExchangeServiceClient()) 
     { 
      client.ClientCredentials.UserName.UserName = "test"; 
      client.ClientCredentials.UserName.Password = "test"; 
      var data = client.RetrieveData(); 
     } 
    } 

Lorsque je mets le mode de transport à "Aucun" dans le nœud de sécurité dans le Serv fichier config de glace les travaux ci-dessus parfaitement si je laisse de côté les lignes d'informations d'identification, mais dès que je changer pour Basic Je continue à obtenir cette erreur:

There was no endpoint listening at https://server.com:446/DataExchangeService/DataExchangeService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 

Je ne sais pas vraiment ce qui se passe si quelqu'un peut me guider de toute façon qui serait extrêmement utile.

Merci

Répondre

9

Je pense que ce que vous voulez vraiment ici est d'utiliser TransportWithMessageCredential au lieu de simplement Transport. L'utilisation de <security mode="Transport"> fera passer votre service HTTPS mais n'a rien à voir avec l'utilisation des informations d'authentification. Si vous utilisez <security mode="TransportWithMessageCredential">, vous pouvez utiliser HTTPS et avoir un nom d'utilisateur et mot de passe. Here est un article MSDN à ce sujet.

EDIT

Si vraiment vous ne voulez juste utiliser Transport, prenez le nœud <message> de configuration de votre service.

+0

merci !!! tu es une saveur de vie! – zSynopsis

Questions connexes