I need to consume a WCF service but I'm behind a proxy server and this proxy server requires a username and password.
I can't find a way to set it, if it was a Web Service, I could just do something like
ws.Proxy = myProxyServer;
How can I do this with a WCF service?
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");
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.
Note replaced previous answer based on comment
There was actually another stackoverflow answer that covered setting credentials on a proxy.
Is it possible to specify proxy credentials in your web.config?