2011-10-22 71 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 –

相关问题