views:

52

answers:

3

Hi,

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 ?

A: 

This should cover it: http://msdn.microsoft.com/en-us/library/ms733775.aspx (See the Client section)

Peladao
A: 

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="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  <soap:Header>
    <AUTHHEADER xmlns="http://tempuri.org/"&gt;
      <USERNAME>string</USERNAME>
      <PASSWORD>string</PASSWORD>
    </AUTHHEADER>
  </soap:Header>
  <soap:Body>
    <SENSITIVEDATA xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>
InSane
A: 

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>
  <basicHttpBidning>
    <binding name="BasicAuth">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

Setup for HTTPS binding:

<bindings>
  <basicHttpBidning>
    <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 = "...";

Best regards, Ladislav

Ladislav Mrnka