1

I need to make a WCF service call to an external 3rd party using 2-way SSL from a class project. I have added the WSDL provided by the 3rd party to my project as a Service Reference. The problem is that all calls outside our domain (*.abc.com) pass through a proxy server

http://ironport:8080

This is what I have done in my code -

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;

I make the service call using -

var account = client.ExportAccounts(obj1, obj2, obj3);

It then gives me an error -

The remote server returned an Error (407): Proxy authentication required

That is but obvious because nowhere did I mention the proxy details the request needs to go through. What I need is a way to add the following info from a web.config file of a different project into my request above -

<system.net>
<defaultProxy useDefaultCredentials="true">
  <proxy proxyaddress="http://ironport:8080" />
  <bypasslist>
    <add address="[\w]+\.abc\.com$" />
  </bypasslist>
</defaultProxy>
</system.net>

Is there some way to achieve this in code? Or do I need to go about this in a different way altogether? Let me know if I need to post more information.

1 Answers1

1

You could try using the WebProxy Class. Not tested, but something like this:

WebProxy proxy = new WebProxy("http://ironport:8080");
proxy.BypassList = new string[] { "[\w]+\.abc\.com$" };

Another alternative would be to move the relevant section of the config to the web/app.config of the application that is using your class library.

ADDED

Not 100% sure this will work, but you could try adding this line to your code:

WebRequest.DefaultProxy = proxy;

Taken from this answer

Another option might be to use the ProxyAddress property of WsHttpBinding (make sure in that case you set the UseDefaultProxy to false), but I don't see a way to add a bypass list with this one.

Community
  • 1
  • 1
Tim
  • 28,212
  • 8
  • 63
  • 76
  • Thanks. I can create a proxy object and populate it with my proxy data but I am unable to associate it in any which way to my service call - `var client = new AccountClient(binding, endpoint); var account = client.ExportAccounts(obj1, obj2, obj3);` The AccountClient class takes in the binding and endpoint objects. No idea where to add the proxy object to. – Himadri Mishra Jan 31 '14 at 17:12
  • @HimadriMishra - See my edit to see if either of these options help. – Tim Jan 31 '14 at 17:32
  • Thanks I can add the proxy details using the `ProxyAddress` property of `WsHttpBinding`. – Himadri Mishra Feb 04 '14 at 14:45