简体   繁体   中英

WCF client calling a Java webservice

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...

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM