How to Set a WCF Client WebProxy

By Peter Bromberg

WCF proxy settings when your WCF client is behind a corporate firewall can be tricky. One easy way to handle this is to create the service proxy in code.

//USAGE:
Service1.YourServiceSoapClient c = new YourServiceSoapClient();
SetProxy(c);
//do operation here

private void SetProxy (Service1.YourServiceSoapClient c)
{
WebProxy proxy = new WebProxy("http://your-proxy-address", true);
proxy.Credentials = new NetworkCredential("username", "password","domain");
WebRequest.DefaultWebProxy = proxy;
var b = c.Endpoint.Binding as System.ServiceModel.BasicHttpBinding;
b.BypassProxyOnLocal = false;
b.UseDefaultWebProxy = true;
}

How to Set a WCF Client WebProxy  (3291 Views)