I use WebClient to load some resource as follows:
Stream stream; try { WebClient webClient = new webClient(); stream = webClient.OpenRead(MyResourceUri); } catch (Exception) { return null; } return stream;
When I do this in a WPF application, it works fine and it gets the correct thread.
When I do this in a WCF service call, it does not work. A WebException message is sent with the message "Unable to connect to remote server" . (It works for files hosted on my machine or inside the companyβs network, however this fails for any resource on the Internet). The service is hosted on IIS7.
Research so far shows that the difference is related to the web proxy. Webclient.proxy in a WPF application refers to the proxy settings set in IE, while it is not in WCF.
Why is that? And more importantly, how can I get WebClient in WCF to use similar proxy settings?
EDIT: I installed the proxy server in WebClient and worked in the WCF service
webClient.Proxy = new WebProxy(ProxyAddressFromIE);
Here I hardcoded the proxy admin. What method / API is there to get it? And yet, why is it different from WCF service and WPF application?
source share