2012-09-20 14 views
11

estoy tratando de consumir un servicio WCF:¿Cómo puedo establecer ClientCredentials?

La configuración del servicio es:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <netNamedPipeBinding> 
       <binding name="netNamedPipeEndpoint" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
        hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" 
        maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <security mode="None"> 
         <transport protectionLevel="EncryptAndSign" /> 
        </security> 
       </binding> 
      </netNamedPipeBinding> 
      <netTcpBinding> 
       <binding name="netTcpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" 
        receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" 
        transferMode="Buffered" transactionProtocol="OleTransactions" 
        hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
        maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" 
        maxReceivedMessageSize="65536"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="None"> 
         <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
         <message clientCredentialType="Windows" /> 
        </security> 
       </binding> 
      </netTcpBinding> 
      <wsHttpBinding> 
       <binding name="wsHttpBindingConfiguration" 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="65536" 
        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="None"> 
         <transport clientCredentialType="Windows" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="net.tcp://webapppro-v11/FlightInfoWebService/FlightInfoService.svc" 
       binding="netTcpBinding" bindingConfiguration="netTcpEndpoint" 
       contract="FlightInfoService" name="netTcpEndpoint" /> 
      <endpoint address="net.pipe://webapppro-v11/FlightInfoWebService/FlightInfoService.svc" 
       binding="netNamedPipeBinding" bindingConfiguration="netNamedPipeEndpoint" 
       contract="FlightInfoService" name="netNamedPipeEndpoint" /> 
      <endpoint address="http://webapppro-v11/FlightInfoWebService/FlightInfoService.svc" 
       binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration" 
       contract="FlightInfoService" name="wsHttpBindingConfiguration" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

Cuando trato de llamar al servicio:

public async void LoadCities() 
{ 
    _client = new FlightInfoServiceClient(Maquette_MyAirport_Win8.FlightService.FlightInfoServiceClient.EndpointConfiguration.wsHttpBindingConfiguration, "http://servuucs.fr/FlightInfoWebService/FlightInfoService.svc"); 

    var citiesResponse = await _client.GetAllCitiesAsync(new BaseRequest()); 
    var myCities = citiesResponse.Cities; 
} 

cojo esta excepción:

ERROR: UnAuthorizedAccess description:You are not authorized to access this service

¿Cómo puedo configurar mis ClientCredentials?

+3

'_client.ClientCredentials' – Paciv

+2

Por favor, publique toda su configuración' '. También por favor formatee para que sea legible. No confíe en la comunidad para arreglar su formateo. Gracias –

+0

Actualicé mi configuración, cualquier sugerencia por favor? – user1428798

Respuesta

22

Como @Paciv señaló en un comentario, puede hacerlo a través del código. Defina por medio de la propiedad ClientCredentials.Windows, algo como esto:

_client.ClientCredentials.Windows.ClientCredential.Domain = "warzone42"; 
_client.ClientCredentials.Windows.ClientCredential.UserName = "user1428798"; 
_client.ClientCredentials.Windows.ClientCredential.Password = "[email protected]"; 

Configuración de las credenciales en el código es, por supuesto, imprudente. Si no configura el usuario de Windows mediante programación como se indicó anteriormente, creo que las credenciales del usuario que ejecuta el cliente se envían de forma cruzada (¿cuál es tal vez una situación más típica?).

Tenga en cuenta que si está configurando credenciales en el código, de hecho, puede estar buscando UserName authentication.

+0

¡Esto no resuelve mi problema! – user1428798

+6

Podría ser. Sin embargo, responde a su pregunta ("¿Cómo puedo establecer las credenciales del cliente?"). – Jeroen

+0

[https://social.msdn.microsoft.com/Forums/vstudio/en-US/0aac0110-187e-4a00-a597-f15b768cf16c/passing-client-credentials-to-wcf-service](https://social .msdn.microsoft.com/Forums/vstudio/es-US/0aac0110-187e-4a00-a597-f15b768cf16c/passing-client-credentials-to-wcf-service) – liuhongbo

Cuestiones relacionadas