[英]Why would Basic Auth not work with my WCF client to Java SOAP Web Service?
I have a Java based web service that requires basic authentication to communicate with it. 我有一个基于Java的Web服务,该服务需要基本身份验证才能与其通信。 If I type the WSDL url into my browser I'm prompted for Basic Auth.
如果我在浏览器中输入WSDL URL,则会提示我输入基本身份验证。 Which I can get by entering the correct credentials.
输入正确的凭证即可获得。
However using my WCF client doesn't work. 但是,使用我的WCF客户端不起作用。
I construct my WCF client like this: 我像这样构造我的WCF客户端:
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?
我要去哪里错了?
I just setup the same thing -- I added a Service Reference in Visual Studio, and it came out similar to what you've done in code. 我只是设置了同一件事-我在Visual Studio中添加了一个Service Reference,它的输出类似于您在代码中所做的。
Two notes though, although it had security mode="Transport" set correctly, it didn't have clientCredentialType="Basic" set. 尽管有两个注意事项,尽管它已正确设置了安全模式=“ Transport”,但未设置clientCredentialType =“ Basic”。 I added to that my config and it still didn't work.
我将其添加到该配置中,但仍然无法正常工作。 Then I actually removed the message security since the service I'm contacting is SSL + Basic only:
然后我实际上删除了消息安全性,因为我联系的服务仅是SSL + Basic:
<message clientCredentialType="UserName" algorithmSuite="Default" />
Voila -- it worked. 瞧-奏效了。
I'm not sure why this had an effect considering the element did not specify message level security... but it did. 考虑到元素未指定消息级别的安全性,我不确定为什么会起作用……但是确实如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.