我需要使用来自类项目的双向SSL向外部第三方发出WCF服务调用。我已经将第三方提供的WSDL添加到我的项目中,作为服务参考。问题是,我们域中的所有调用(*.abc.com)都是通过代理服务器进行的。
http://ironport:8080
这就是我在代码中所做的-
var binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
binding.BypassProxyOnLocal = false;
binding.UseDefaultWebProxy = true;
binding.AllowCookies = false;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
var endpoint = new EndpointAddress("https://blablabla.com/GetData.svc");
var client = new AccountClient(binding, endpoint);
X509Certificate2 certi = new X509Certificate2(@"path to pfx file", "password");
client.ClientCredentials.ClientCertificate.Certificate = certi;
我打服务电话时-
var account = client.ExportAccounts(obj1, obj2, obj3);
它给了我一个错误-
The remote server returned an Error (407): Proxy authentication required
这一点很明显,因为我没有提到请求需要通过的代理细节。我需要一种方法,从一个不同项目的web.config文件中添加以下信息到我上面的请求中-
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy proxyaddress="http://ironport:8080" />
<bypasslist>
<add address="[\w]+\.abc\.com$" />
</bypasslist>
</defaultProxy>
</system.net>
有什么方法可以在代码中实现这一点吗?还是我需要用一种完全不同的方式来做这件事?如果我需要更多的信息,请告诉我。
发布于 2014-01-31 08:44:53
您可以尝试使用WebProxy类。没有经过测试,但像这样的东西:
WebProxy proxy = new WebProxy("http://ironport:8080");
proxy.BypassList = new string[] { "[\w]+\.abc\.com$" };
另一种选择是将配置的相关部分移动到使用类库的应用程序的web/app.config。
添加了
不能100%确定这将有效,但您可以尝试将这一行添加到代码中:
WebRequest.DefaultProxy = proxy;
摘自这个回答
另一种选择可能是使用WsHttpBinding
的WsHttpBinding
属性(确保在这种情况下将UseDefaultProxy
设置为false),但我看不出有什么方法可以添加绕行列表。
https://stackoverflow.com/questions/21478804
复制相似问题