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

发布于 2024-08-25 08:50:18 字数 877 浏览 4 评论 0原文

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

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

是否可以将运行应用程序的已登录用户的详细信息传递给 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"'。

I have written a WPF 4.0 windows application that consumes a .net 3.5 WebService. This works fine when the web service in hosted to allow anonymous connections, however the WebService I need to consume when we go live will be held within a website that has Integrated Authentication enabled.

The person running the WPF application will be logged onto a computer within the same domain as the web server and will have permission to see the WebService (without entering any auth info) if browsing to it using a web browser that is NTLM auth enabled.

Is it possible to pass through the details of the already logged in user running the application to the WebService?

Here is the code I'm currently using:

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

Any pointers much appreciated.

Here is the error message I get when the call is currently made:

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"'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可是我不能没有你 2024-09-01 08:50:18

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

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

So it turns out that the solution to this problem is very simple in my case.

In the binding configuration for WebService in the App.Config file, I changed this:

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

To this:

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

Note I changed the Mode and clientCredentialType attributes.

And in the Code Behind I added this line before calling the method on the WebService:

client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文