title: WCF service call from class project with proxy
body: <p>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</p>
  
  <pre><code>http://ironport:8080
  </code></pre>
  
  <p>This is what I have done in my code - </p>
  
  <pre><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;
  </code></pre>
  
  <p>I make the service call using -</p>
  
  <pre><code>var account = client.ExportAccounts(obj1, obj2, obj3);
  </code></pre>
  
  <p>It then gives me an error - </p>
  
  <pre><code>The remote server returned an Error (407): Proxy authentication required
  </code></pre>
  
  <p>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 - </p>
  
  <pre><code>&lt;system.net&gt;
  &lt;defaultProxy useDefaultCredentials="true"&gt;
    &lt;proxy proxyaddress="http://ironport:8080" /&gt;
    &lt;bypasslist&gt;
      &lt;add address="[\w]+\.abc\.com$" /&gt;
    &lt;/bypasslist&gt;
  &lt;/defaultProxy&gt;
  &lt;/system.net&gt;
  </code></pre>
  
  <p>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.</p>