繁体   English   中英

为什么基本身份验证无法与我的Java SOAP Web服务的WCF客户端一起使用?

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

我有一个基于Java的Web服务,该服务需要基本身份验证才能与其通信。 如果我在浏览器中输入WSDL URL,则会提示我输入基本身份验证。 输入正确的凭证即可获得。

但是,使用我的WCF客户端不起作用。

我像这样构造我的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();

我得到以下异常。

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

据我所知,我在做正确的事。 我要去哪里错了?

我只是设置了同一件事-我在Visual Studio中添加了一个Service Reference,它的输出类似于您在代码中所做的。

尽管有两个注意事项,尽管它已正确设置了安全模式=“ Transport”,但未设置clientCredentialType =“ Basic”。 我将其添加到该配置中,但仍然无法正常工作。 然后我实际上删除了消息安全性,因为我联系的服务仅是SSL + Basic:

<message clientCredentialType="UserName" algorithmSuite="Default" />

瞧-奏效了。

考虑到元素未指定消息级别的安全性,我不确定为什么会起作用……但是确实如此。

暂无
暂无

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

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