.net - 从 WPF Windows 应用程序使用具有集成身份验证的 WebService

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

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

运行 WPF 应用程序的人员将登录到与 Web 服务器位于同一域中的计算机,并且如果使用 NTLM 身份验证的 Web 浏览器浏览该 WebService,则将有权查看 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();

非常感谢任何指点。

以下是当前调用电话时收到的错误消息:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM,Digest qop="auth",algorithm=MD5-sess,nonce="+Upgraded+v17{hashremoved}",charset=utf-8,realm="Digest"'.

最佳答案

事实证明,就我而言,这个问题的解决方案非常简单。

在 App.Config 文件中 WebService 的绑定(bind)配置中,我更改了以下内容:

<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;

关于.net - 从 WPF Windows 应用程序使用具有集成身份验证的 WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2476290/

相关文章:

c# - 循环中的 Sql 请求会减慢 C# 应用程序的速度

c# - VS 代码 : How to copy files to output directory depending on build configurations

c# - Entity Framework 6 未使用属性正确映射我的列

c# - 快速将 Bitmap 转换为 BitmapSource wpf

wpf - 在 WPF 中设置鼠标悬停在按钮上的边框大小

windows - 如何在 Windows 上通过 SSH 自动运行命令

c# - Response.Redirect 属于哪个命名空间?

c# - 为什么使用 Task.ContinueWith 会损害我的程序的响应能力?

windows - 你能在 VBScript MsgBox 中的按钮之间输入 'mix and match' 吗?

c# - 查找网络中的所有IP地址