【问题标题】:Consume a WebService with Integrated authentication from WPF windows application从 WPF windows 应用程序使用具有集成身份验证的 WebService
【发布时间】:2010-03-19 09:56:47
【问题描述】:

我编写了一个使用 .net 3.5 WebService 的 WPF 4.0 Windows 应用程序。当托管的 Web 服务允许匿名连接时,这可以正常工作,但是当我们上线时我需要使用的 WebService 将保存在启用了集成身份验证的网站中。

运行 WPF 应用程序的人将登录到与 Web 服务器位于同一域中的计算机上,并且如果使用 NTLM auth 的 Web 浏览器浏览它,则有权查看 WebService(无需输入任何身份验证信息)已启用。

是否可以将运行应用程序的已登录用户的详细信息传递给 WebService?

这是我目前正在使用的代码:

MyWebService.SearchSoapClient client = new SearchSoapClient();
//From the research I've done I think I need to something with these:
//UserName.PreAuthenticate = true;
//System.Net.CredentialCache.DefaultCredentials;
List<Person> result = client.FuzzySearch("This is my search string").ToList();

任何指针都非常感谢。

这是我当前拨打电话时收到的错误消息:

HTTP 请求未经授权 客户端认证方案 '匿名的'。身份验证标头 从服务器收到的是 '协商、NTLM、摘要 qop="auth",algorithm=MD5-sess,nonce="+Upgraded+v17{hashremoved}",charset=utf-8,realm="Digest"'。

【问题讨论】:

    标签: .net wpf windows web-services windows-authentication


    【解决方案1】:

    所以事实证明,这个问题的解决方案对我来说非常简单。

    在 App.Config 文件中的 WebService 绑定配置中,我更改了这个:

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

    到这里:

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

    注意我更改了 Mode 和 clientCredentialType 属性。

    在后面的代码中,我在调用 WebService 上的方法之前添加了这一行:

    client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      相关资源
      最近更新 更多