web service proxy setting

Fidel picture Fidel · Mar 5, 2011 · Viewed 32.8k times · Source

In c# 4.0, I have a web service called ManufacturerContactDetails. I am calling that web service from a windows app using the following:

var ws = new ManufacturerContactDetailsWebServiceSoapClient();
ContactDetails cd = ws.GetContactDetails("Google");

However, I would like to set the web proxy server that the soap client uses. I've had a look for a ws.Proxy property but it doesn't exist. I don't want to use the one from internet explorer.

How do I set the web proxy server to use?

Answer

Darin Dimitrov picture Darin Dimitrov · Mar 5, 2011

If this is a WCF client there is no Proxy property. You could try this instead:

var proxy = new WebProxy("proxy.foo.com", true);
proxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = proxy;

and then do the call:

using (var ws = new ManufacturerContactDetailsWebServiceSoapClient())
{
    var cd = ws.GetContactDetails("Google");
}