2011-10-22 135 views
4

我需要從c#表單應用訪問Web服務。使用Soap客戶端進行Windows身份驗證的Web服務

該webservice需要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驗證,而不是匿名?

回答

6

如果有人仍然需要這個,我很高興今天能找到它。這的確是很簡單:

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

似乎AllowNtlm已被棄用,並且它使用計算機設置,你知道如何在Windows 7中啓用NTLM嗎? – guiomie

+0

我收到了相同的折舊警告。我能夠得到它的工作,遵循這個:https://msdn.microsoft.com/en-us/library/ms732391.aspx –

相關問題