【问题标题】:Why would Basic Auth not work with my WCF client to Java SOAP Web Service?为什么 Basic Auth 不适用于我的 WCF 客户端到 Java SOAP Web 服务?
【发布时间】:2010-04-30 06:53:42
【问题描述】:

我有一个基于 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"'.

据我所知,我做的事情是正确的。我哪里错了?

【问题讨论】:

    标签: c# java wcf soap basic-authentication


    【解决方案1】:

    我只是设置了相同的东西——我在 Visual Studio 中添加了一个服务引用,结果与您在代码中所做的类似。

    有两个注意事项,虽然它正确设置了安全模式="Transport",但没有设置 clientCredentialType="Basic"。我添加了我的配置,但它仍然无法正常工作。然后我实际上删除了消息安全性,因为我正在联系的服务仅是 SSL + Basic:

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

    瞧——它奏效了。

    考虑到元素没有指定消息级别的安全性,我不确定为什么这会产生影响......但确实如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多