簡體   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