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 = "...";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…