One of my xbap project I was creating wcf proxy using channel factory but all wcf call fail on a machine(actually all pc under a network) that only connect Internet through a proxy server. then after detail investigation I'm discover that if you are create wcf proxy using channel factory its ignore the configuration useDefaultWebProxy="true" and try to connect with Internet by pass the proxy server. I'm found it by monitor raw packet using YATT.
But in case of auto generated proxy its simply working fine. if you user useDefaultWebProxy="true" in your binding its not by pass proxy server.
to full proof that your apps following the default proxy settings on a machine you can add following code at start up
public App()
{
WebRequest.DefaultWebProxy = System.Net.WebRequest.GetSystemWebProxy();
//to get default proxy settings
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
try
{
WebRequest request = System.Net.WebRequest.Create(
"http://www.labla.com/lablabla.html");
request.GetResponse();
}
catch (Exception ex)
{
if (ex.Message.Equals("The remote server returned an error: (407) Proxy Authentication Required."))
{
//Proxy Authentication Required.
//WebRequest.DefaultWebProxy.Credentials = new NetworkCredential(c.UserName, c.Pass);
}
}
}
hope this help…
0 comments:
Post a Comment