【问题标题】:Web Service with Windows Authentication with Soap Client使用 Soap 客户端进行 Windows 身份验证的 Web 服务
【发布时间】:2011-10-22 22:08:02
【问题描述】:

我需要从 c# 表单应用程序访问网络服务。

网络服务需要 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 身份验证,而不是匿名?

【问题讨论】:

    标签: c# wcf web-services


    【解决方案1】:

    如果有人仍然需要这个,我今天很高兴解决了这个问题。真的很简单:

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

    【讨论】:

    • AllowNtlm 似乎已被弃用,而且它使用计算机设置,你知道如何在 windows 7 中启用 NTLM 吗?
    • 我收到了同样的折旧警告。我能够让它工作,遵循这个:msdn.microsoft.com/en-us/library/ms732391.aspx
    【解决方案2】:

    在客户端 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)

    【讨论】:

      猜你喜欢
      • 2012-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多