tags:

views:

1669

answers:

2

Hello, 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?

thanks!

+1  A: 

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.

Eduardo Scoz
what about the username and password?
Hi Hans, I just added extra info. Can you try that? I have not used it, but it should work.
Eduardo Scoz
@Eduardo: he's using WCF. Are you certain that WCF uses the WebRequest.DefaultProxy property?
John Saunders
@John - actually - yes! I was surprised myself, too - but check out this link here: http://blogs.msdn.com/stcheng/archive/2008/12/03/wcf-how-to-supply-dedicated-credentials-for-webproxy-authentication.aspx
marc_s
I actually had a problem with it the other day and that's how I found about it. The option was enabled in the app.config, but no proxy was configured. Somebody then decided to access the web on the performance test server and set up proxy, which made everything stop working..
Eduardo Scoz
Actually you need to set useDefaultWebProxy="false" to use the proxy that you configure
David
A: 

Note replaced previous answer based on comment

There was actually another stackoverflow answer that covered setting credentials on a proxy.

http://stackoverflow.com/questions/186800/is-it-possible-to-specify-proxy-credentials-in-your-web-config

Shiraz Bhaiji
I think he wants to be able to set authentication for the proxy server. Also, it might help to show how the code would set them: where did "client" come from in your example, for instance?
John Saunders
yes.... authentication for the proxy server...