title: How can I set an HTTP Proxy (WebProxy) on a WCF client-side Service proxy?
body: <p>How can I set the HTTP proxy programmatically, on a WCF client, without using the default proxy?  </p>
  
  <p>Proxies, proxies, proxies. </p>
  
  <p>According to the WCF model of development, I generate client-side "proxy"
  classes by running svcutil.exe on the WSDL for the service.  (This also
  produces a client-side config file).</p>
  
  <p>In my code I new-up an instance of that class and I can connect to the
  service. Very nice.</p>
  
  <pre><code>var svcProxy = new MyWebService();
  svcProxy.GetInformation(request); 
  </code></pre>
  
  <p>We call this thing a proxy class, but there is another proxy - the http proxy.  This
  service is using wsHttpBinding basicHttpBinding, so it is going over
  http.  Now, suppose I want to connect the client to the web service over
  a http proxy (modeled by a System.Net.WebProxy in the .NET BCL).  I know
  from my extensive, delightful experience reading .NET and WCF documentation, that
  the WCF runtime, if not instructed otherwise, will use the default
  system proxy when communicating over http/https.  </p>
  
  <p>I can set that from the command line in
  WinXP / 2003 <a href="http://support.microsoft.com/kb/830605" rel="noreferrer">with ProxyCfg.exe as described here</a>, and in later
  versions of Windows <a href="http://blogs.msdn.com/wndp/archive/2007/03/21/winhttp-configuration-for-windows-vista.aspx" rel="noreferrer">with netsh.exe as described here</a>.</p>
  
  <p>I can also specify the default web proxy for use within the application
  by setting the <a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx" rel="noreferrer">System.Net.WebRequest.DefaultWebProxy property</a>. </p>
  
  <p>But suppose I want to connect over a proxy that is different than the
  system-wide proxy? For instance maybe there is no system-wide proxy but
  I need to use one for the web service in particular.   Or maybe there is
  a system-wide proxy but I need to use a different one, for the web
  service. And in fact maybe there are multiple web service clients, and
  each one should get a different proxy. </p>
  
  <p>How can the proxy be set per-binding? </p>
  
  <p>In the ASMX model, I could do this: </p>
  
  <pre><code>var svcProxy = new MyWebService();
  svcProxy.Proxy = new System.Net.WebProxy("http://proxyserver:1234", true);
  svcProxy.GetInformation(request); 
  </code></pre>
  
  <p>But this is not possible with WCF; the WCF-generated client-side proxy
  classes do not expose a Proxy property.  How do I set the http proxy, per client-side proxy, and how do I set authentication on the http proxy as well?  </p>
  
  <blockquote>
    <p>Related:<br>
    - <a href="https://stackoverflow.com/questions/105499/how-to-set-proxy-with-credentials-to-generated-wcf-client">how-to-set-proxy-with-credentials-to-generated-wcf-client</a></p>
  </blockquote>