I'm trying to consume a WCF service:

The config of the service is:

<?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="" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfiguration" contract="FlightInfoService" name="wsHttpBindingConfiguration" /> </client> </system.serviceModel> </configuration> 

When I try to call the service:

public async void LoadCities() { _client = new FlightInfoServiceClient(Maquette_MyAirport_Win8.FlightService.FlightInfoServiceClient.EndpointConfiguration.wsHttpBindingConfiguration, ""); var citiesResponse = await _client.GetAllCitiesAsync(new BaseRequest()); var myCities = citiesResponse.Cities; } 

I catch this exception:

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

How can I set my ClientCredentials?

3

1 Answer

As @Paciv noted in a comment, you can do this through code. Set them with the property ClientCredentials.Windows, something like this:

_client.ClientCredentials.Windows.ClientCredential.Domain = "warzone42"; _client.ClientCredentials.Windows.ClientCredential.UserName = "user1428798"; _client.ClientCredentials.Windows.ClientCredential.Password = "p@ssw0rd"; 

Setting the credentials in code is of course unwise. If you don't set the Windows user programmatically as above, I believe the credentials from the user running the client are sent accross (which is perhaps a more typical situation?).

Note that if you're setting credentials in code you may in fact be looking for UserName authentication.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.