Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么Basic Auth不能与我的WCF客户机一起工作到javasoapweb服务?_C#_Java_Wcf_Soap_Basic Authentication - Fatal编程技术网

C# 为什么Basic Auth不能与我的WCF客户机一起工作到javasoapweb服务?

C# 为什么Basic Auth不能与我的WCF客户机一起工作到javasoapweb服务?,c#,java,wcf,soap,basic-authentication,C#,Java,Wcf,Soap,Basic Authentication,我有一个基于Java的web服务,需要基本的身份验证才能与之通信。如果我在浏览器中键入WSDL url,系统会提示我输入基本身份验证。我可以通过输入正确的凭据来获取 但是,使用我的WCF客户端不起作用 我的WCF客户端是这样构造的: var binding = new BasicHttpBinding { MaxReceivedMessageSize = 2048 * 10240, Security = { Mode = BasicHttpSecurityMode.Transpo

我有一个基于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中添加了一个服务引用,结果与您在代码中所做的类似

不过有两个注意事项,虽然它正确设置了security mode=“Transport”,但没有设置clientCredentialType=“Basic”。我添加了我的配置,但仍然不起作用。然后我实际上删除了消息安全性,因为我正在联系的服务仅限于SSL+Basic:

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

瞧,成功了

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