消费与WPF windows应用程序集成的身份验证一个WebService [英] Consume a WebService with Integrated authentication from WPF windows application

查看:250
本文介绍了消费与WPF windows应用程序集成的身份验证一个WebService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了WPF 4.0的Windows应用程序消耗了.NET 3.5的WebService。这正常工作时,在托管的Web服务,以允许匿名连接,但我需要的WebService的时候,我们去住将是一个网站,有集成身份验证启用内举行消耗。

运行WPF应用程序的人,如果使用的Web浏览器是NTLM身份验证浏览到它会被登录到一台计算机的同一个域中的Web服务器中,将有权限看到的WebService(无需输入任何验证信息)启用。

可以通过它通过对已经登录的详细信息,在用户运行的应用程序,以WebService的?

下面是我目前使用的code:

  MyWebService.SearchSoapClient客户端=新SearchSoapClient();
//从我已经做了我想我需要的东西与这些研究:
//UserName.$p$pAuthenticate = TRUE;
//System.Net.CredentialCache.DefaultCredentials;
名单<人>结果= client.FuzzySearch(这是我的搜索字符串)了ToList()。
 

任何指针多少AP preciated。

下面是我得到的时候调用目前所做的错误消息:

  

中的HTTP请求是未经授权   客户端身份验证方案   '匿名'。认证头   从服务器接收为   协商,NTLM,摘要   QOP =身份验证,算法= MD5-SESS,随机数=+升级+ V17 {hashremoved},字符集= UTF-8,境界=消化。

解决方案

所以,事实证明,要解决这个问题,在我的情况很简单。

在对WebService的app.config文件中的绑定配置,我改变了这一点:

 <安全模式=无>
  <交通运输clientCredentialType =无proxyCredentialType =无的境界=/>
 <消息clientCredentialType =用户名algorithmSuite =默认/>
< /安全>
 

要这样:

 <安全模式=TransportCredentialOnly>
 <交通运输clientCredentialType =窗口proxyCredentialType =无的境界=/>
 <消息clientCredentialType =用户名algorithmSuite =默认/>
< /安全>
 

请注意,我改变了模式和clientCredentialType属性。

而在code后面我呼吁WebService的方法前加入这一行:

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

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

解决方案

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;

这篇关于消费与WPF windows应用程序集成的身份验证一个WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆