簡體   English   中英

使用Soap Client進行Windows身份驗證的Web服務

[英]Web Service with Windows Authentication with Soap Client

我需要從ac#forms app訪問web服務。

Web服務需要Windows身份驗證。

我使用以下代碼:

ServiceDeskSoapClient sd = new ServiceDeskSoapClient();
sd.ClientCredentials.UserName.UserName = @"mydomain\myusername";
sd.ClientCredentials.UserName.Password = "mypassword";
sd.MyMethod();

但是得到以下錯誤:

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

如何正確設置憑據,以便它使用Windows身份驗證,而不是匿名?

在客戶端的app.config中的<binding>部分中添加以下內容:

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

(來自http://morrisbahrami.blogspot.com.au/2011/02/http-request-is-unauthorized-with.html

如果有人仍然需要這個,我很高興今天搞清楚。 這真的很簡單:

var server = new MySoapClient();
if (server.ClientCredentials != null)
{
    server.ClientCredentials.Windows.AllowNtlm = true;
    server.ClientCredentials.Windows.ClientCredential = new NetworkCredential("MyUsername", "MyPassword", "MyDomain");
}

暫無
暫無

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

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