Why would Basic Auth not work with my WCF client to Java SOAP Web Service?

Posted by orj on Stack Overflow See other posts from Stack Overflow or by orj
Published on 2010-04-30T06:53:42Z Indexed on 2010/04/30 6:57 UTC
Read the original article Hit count: 612

Filed under:
|
|
|
|

I have a Java based web service that requires basic authentication to communicate with it. If I type the WSDL url into my browser I'm prompted for Basic Auth. Which I can get by entering the correct credentials.

However using my WCF client doesn't work.

I construct my WCF client like this:

var binding = new BasicHttpBinding
{
  MaxReceivedMessageSize = 2048 * 10240,
  Security = {
    Mode = BasicHttpSecurityMode.TransportCredentialOnly, 
    Transport = {
      ClientCredentialType = HttpClientCredentialType.Basic,
      Realm = "MYREALM",
      ProxyCredentialType = HttpProxyCredentialType.None
    }, 
    Message = {
      ClientCredentialType = BasicHttpMessageCredentialType.UserName,
      AlgorithmSuite = SecurityAlgorithmSuite.Default
    }
  }
};

var client = new WebServiceClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;
client.DoWebServiceMethod();

I get the following exception.

System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm="MYREALM"'.

From what I can tell I'm doing things right. Where am I going wrong?

© Stack Overflow or respective owner

Related posts about wcf

Related posts about c#