簡體   English   中英

使用NTLM身份驗證的SOAP Web服務調用無法正常工作C#

[英]SOAP web service call with NTLM auth not working C#

我正在嘗試使用NTLM身份驗證進行SOAP Web服務調用,但它不起作用。

我使用了WSDL服務。

到目前為止我做了什么:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://uri.test/");
_client = new TEST_PortClient(binding, address);

if (_client.ClientCredentials != null)
{
  _client.ClientCredentials.Windows.AllowNtlm = true; // this method is deprecated
  _client.ClientCredentials.Windows.ClientCredential.UserName = "username";
  _client.ClientCredentials.Windows.ClientCredential.Password = "password";
}
_client.Open(); // this works successfully
string message = string.Empty;
if (_client.TestConnection(ref message)) // this throw an exception *
{
  // do something
}

拋出的異常是:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.

我該怎么辦才能使它有效?

我用這種方式解決了它:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress(Uri);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

binding.MessageEncoding = WSMessageEncoding.Text;
binding.TextEncoding = Encoding.UTF8;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

_client = new TEST_PortClient(binding, address);

if (_client.ClientCredentials != null)
{
  _client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password");
  _client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;

}
_client.Open();

string message = string.Empty;
if (_client.TestConnection(ref message))
{
  // do something
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM