0
votes

I have a small issue logging in with a webservice being hosted using HTML with basic authentication. I have tried the following but it does not work. Are there any restrictions or gotchas on this?

           var client = new WSClient();
           client.ClientCredentials.UserName.UserName = "xxx";
           client.ClientCredentials.UserName.Password = "yyy";
           client.doIt();

The client shows an exception with the http 401 unauthorized code, but it does not attempt to login. The client is using WCF and is generated by Visual Studio 2008, server is running Java Apache CXF. The basic challenge works fine using a webbrowser...

1

1 Answers

1
votes

After some investigation this does an login:

var binding = new BasicHttpBinding();
binding.Security.Mode=BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType=HttpClientCredentialType.Basic;
var client = new WSClient(binding, new EndpointAddress("http://localhost/myws"));
client.ClientCredentials.UserName.UserName = "xxx";
client.ClientCredentials.UserName.Password = "yyy";
client.doIt();