WCF 服务的代理服务器身份验证 [英] Proxy server authentication for WCF service

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

问题描述

我需要使用 WCF 服务,但我在代理服务器后面,而该代理服务器需要用户名和密码.

I need to consume a WCF service but I'm behind a proxy server and this proxy server requires a username and password.

我找不到设置它的方法,如果它是 Web 服务,我可以做类似的事情

I can't find a way to set it, if it was a Web Service, I could just do something like

ws.Proxy = myProxyServer;

如何使用 WCF 服务执行此操作?

How can I do this with a WCF service?

推荐答案

在 WCF 绑定配置中,使用 useDefaultWebProxy 属性使 WCF 使用 windows 默认代理(可以从 IE 网络配置中设置):

In the WCF binding config, use the useDefaultWebProxy property to make WCF use the windows default proxy (which can be set from IE network config):

<bindings>
<basicHttpBinding>
<binding name="ESBWSSL" ...everything...  useDefaultWebProxy="true">

然后在代码中,在使用连接之前,这样做:

Then in the code, before you use the connection, do this:

WebProxy wproxy = new WebProxy("new proxy",true);
wproxy.Credentials = new NetworkCredential("user", "pass");

并使用您的 webrequest 对象,在您执行调用之前:

and with your webrequest object, before you execute the call:

WebRequest.DefaultWebProxy = wproxy;

我还没有测试过代码,但我相信这应该可行.

I have not tested the code, but I believe this should work.

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

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