我编写了一个使用 .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/