简体   繁体   English

WCF客户端调用Java Web服务

[英]WCF client calling a Java webservice

I have a small issue logging in with a webservice being hosted using HTML with basic authentication. 使用基本身份验证使用HTML托管的Web服务登录时,我遇到一个小问题。 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. 客户端显示带有HTTP 401未授权代码的异常,但不会尝试登录。 The client is using WCF and is generated by Visual Studio 2008, server is running Java Apache CXF . 客户端使用WCF,由Visual Studio 2008生成,服务器运行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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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