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 ?


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:

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

Setup for HTTPS binding:

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

Client endpoint has to use defined configuration like:

  <endpoint address="..." 
            contract="..."  />

Then you have to pass credentials to the proxy:

proxy = new MyServiceClient();
proxy.ClientCredentials.UserName.UserName = "...";
proxy.ClientCredentials.UserName.Password = "...";

This should cover it: (See the Client section)

I would say it is likely to depend on how the web service expects you to pass the information. After all, you are only the consumer.

Having said that, it is common is web services to have the userid and password passed in the SOAP Header.

You can refer to this link for a sample implementation of this scenario

Sample Soap Message

<soap:Envelope xmlns:soap="">
    <AUTHHEADER xmlns="">
    <SENSITIVEDATA xmlns="" />

Need Your Help

Converting JSON to XLS/CSV in Java

java json excel csv xls

Does anyone have any sample Java code to convert a JSON document to XLS/CSV file? I have tried to search on Google but to no avail.

Dojo and unregistering widgets

dojo widget toolkit

I am new to the Dojo Toolkit. I'm getting the error