Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a web service that requires basic http authentication from wcf client

I have a wsdl from a web service, I generated the wcf proxy. No problem.

But I can not get my head around how to pass the user name and password. The webservice requires basic authentication - only username and password.

Any help ?

like image 910
Vladimir Georgiev Avatar asked Aug 16 '10 18:08

Vladimir Georgiev


People also ask

How do I use HTTP basic authentication?

HTTP basic authentication is a simple challenge and response mechanism with which a server can request authentication information (a user ID and password) from a client. The client passes the authentication information to the server in an Authorization header. The authentication information is in base-64 encoding.


1 Answers

Is Basic authentication configured in configuration file? Do you need to pass only credentials or do you also need secured transport (HTTPS)?

First you need to set up binding to support Basic authentication

Setup for HTTP binding:

<bindings>
  <basicHttpBinding>
    <binding name="BasicAuth">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

Setup for HTTPS binding:

<bindings>
  <basicHttpBinding>
    <binding name="BasicAuthSecured">
      <security mode="Transport">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

Client endpoint has to use defined configuration like:

<client>
  <endpoint address="..." 
            name="..." 
            binding="basicHttpBinding" 
            bindingConfiguration="BasicAuth" 
            contract="..."  />
</client>

Then you have to pass credentials to the proxy:

proxy = new MyServiceClient();
proxy.ClientCredentials.UserName.UserName = "...";
proxy.ClientCredentials.UserName.Password = "...";
like image 75
Ladislav Mrnka Avatar answered Sep 27 '22 18:09

Ladislav Mrnka