WCF自定义HTTP代理验证 [英] WCF Custom Http Proxy Authentication

查看:380
本文介绍了WCF自定义HTTP代理验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能提供WCF使用自定义代理服务器地址和自定义的凭据?

Is it possible to provide WCF with a custom proxy address and custom credentials?

我发现在计算器这样的回答:<一href=\"http://stackoverflow.com/questions/105499/how-to-set-proxy-with-credentials-to-generated-wcf-client\">http://stackoverflow.com/questions/105499/how-to-set-proxy-with-credentials-to-generated-wcf-client,但我有一个复杂的,我对认证服务使用自己的身份验证,所以我必须用两组凭证(一个通过代理来获得,而另对服务进行身份验证)

I've found this answer on stackoverflow: http://stackoverflow.com/questions/105499/how-to-set-proxy-with-credentials-to-generated-wcf-client, but I've got a complication, the service I'm authenticating against uses its own authentication, so I've got to use two sets of credentials (one to get through the proxy, and the other to authenticate against the service)

我使用的回答其他问题描述的技术,以提供服务的凭证。例如。

I'm using the technique described in the answers to the other question to provide the service credentials. e.g.

client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;

我可以使用像这样设置代理服务器的地址:

I can set the address of the proxy using something like this:

(client.Endpoint.Binding as WSHttpBinding).ProxyAddress = ...;

我如何设置什么是有效两组凭证? (注:为代理和实际服务的凭证是不同的!)另外请注意,代理细节不一定是默认的系统代理细节

How do I set what is effectively two sets of credentials? (NB: The credentials for the proxy and the actual service are different!) Also note that the proxy details are not necessarily the default system proxy details.

推荐答案

如果您设置的<一个href=\"http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx\">WebRequest.DefaultWebProxy财产与凭证的新WebProxy,WCF将使用它,它使所有HTTP请求。 (这将影响应用程序所使用的所有HttpWebRequests除非明确覆盖)。

If you set the WebRequest.DefaultWebProxy property to a new WebProxy with credentials, WCF will use it for all HTTP requests that it makes. (This will affect all HttpWebRequests used by the application unless explicitly overridden).

// get this information from the user / config file / etc.
Uri proxyAddress;
string userName;
string password;

// set this before any web requests or WCF calls
WebRequest.DefaultWebProxy = new WebProxy(proxyAddress)
{
    Credentials = new NetworkCredential(userName, password),
};

帖子包含更多详细信息的代理服务器上。

My blog post on proxy servers contains further details.

这篇关于WCF自定义HTTP代理验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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