I have written a WCF client which consumes a 3rd party web service.

I used the Visual Studio "Add Service Reference" wizard, and have used the code that it created without a hitch. It is great.

Once I had my client tested on my own development PC and then again on another PC (where internet access is different), I started deploying my WCF client to customers. It is now installed at over 20 sites and working well.

Except: at the latest customer, it will not work because their internet connection is set up to access the internet via a proxy server, and my WCF client fails with status 407.

Now, I know what the proxy server's IP address is, and the user name and password needed to authenticate to it. What I don't know is how I provide those three things to WCF so that it will authenticate with the proxy server for me.

I have tried using

MyWcfClient.ClientCredentials.UserName.UserName = proxyUsername;
MyWcfClient.ClientCredentials.UserName.Password = proxyPassword;

But that doesn't help.

I have searched around various forums for answers to this problem, and have tried some of the suggested solutions, but they seem to revolve around Windows authentication, and seem to be very, very complicated. And my application isn't really all that complicated - as I said above, it works with just the straight code as generated by the VS Service Reference wizard.

How can I specify the proxy's IP address, user name and password so that WCF will authenticate with the proxy for me?

I am experiencing the exact same problem. Has anyone answered this yet, or have you figured out how to get around this?


I have written a WCF client which consumes a 3rd party web service.

I used the Visual Studio "Add Service Reference" wizard, and have used the code that it created without a hitch. It is great.

Once I had my client tested on my own development PC and then again on another PC (where internet access is different), I started deploying my WCF client to customers. It is now installed at over 20 sites and working well.

Except: at the latest customer, it will not work because their internet connection is set up to access the internet via a proxy server, and my WCF client fails with status 407.

Now, I know what the proxy server's IP address is, and the user name and password needed to authenticate to it. What I don't know is how I provide those three things to WCF so that it will authenticate with the proxy server for me.

I have tried using

MyWcfClient.ClientCredentials.UserName.UserName = proxyUsername;
MyWcfClient.ClientCredentials.UserName.Password = proxyPassword;

But that doesn't help.

I have searched around various forums for answers to this problem, and have tried some of the suggested solutions, but they seem to revolve around Windows authentication, and seem to be very, very complicated. And my application isn't really all that complicated - as I said above, it works with just the straight code as generated by the VS Service Reference wizard.

How can I specify the proxy's IP address, user name and password so that WCF will authenticate with the proxy for me?

I am experiencing the exact same problem. Has anyone answered this yet, or have you figured out how to get around this?

I should have posted the solution here when I found it, forgive me.
But this is what worked in the end:

BasicHttpBinding binding = new BasicHttpBinding("APISoap"); /* APISoap is the name of the binding element in the app.config */
    binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
    binding.UseDefaultWebProxy = false;
    binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyIpAddress, proxyPort)); 
    EndpointAddress endpoint = new EndpointAddress("http://www.examplewebservice/api.asmx");

    WebServiceClient client = new WebServiceClient(binding, endpoint);

    client.ClientCredentials.UserName.UserName = proxyUserName;
    client.ClientCredentials.UserName.Password = proxyPassword;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.