使用Soap客户端进行Windows身份验证的Web服务
问题描述:
我需要从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验证,而不是匿名?
答
如果有人仍然需要这个,我很高兴今天能找到它。这的确是很简单:
var server = new MySoapClient();
if (server.ClientCredentials != null)
{
server.ClientCredentials.Windows.AllowNtlm = true;
server.ClientCredentials.Windows.ClientCredential = new NetworkCredential("MyUsername", "MyPassword", "MyDomain");
}
答
添加<结合>段内按照客户的app.config:
<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)
似乎AllowNtlm已被弃用,并且它使用计算机设置,你知道如何在Windows 7中启用NTLM吗? – guiomie
我收到了相同的折旧警告。我能够得到它的工作,遵循这个:https://msdn.microsoft.com/en-us/library/ms732391.aspx –