How can I set an HTTP Proxy (WebProxy) on a WCF client-side Service proxy?

后端 未结 5 740
孤独总比滥情好
孤独总比滥情好 2020-11-29 00:57

How can I set the HTTP proxy programmatically, on a WCF client, without using the default proxy?

Proxies, proxies, proxies.

According to the WCF model of

5条回答
  •  隐瞒了意图╮
    2020-11-29 01:25

    I have had a similar problem, but I also needed to use a username and password for the proxy that differ from the username and password used to access the service.

    I tried building it up through a UriBuilder, which would output the proxy address as "http://username:password@myproxyserver/". Unfortunately, the particular proxy I was using didn't work with this technique.

    What I found after extensive Googling, is that you can change the proxy through WebRequest.DefaultProxy (static property).

    For example:

    WebProxy proxy = new WebProxy("http://myproxyserver",true);
    proxy.Credentials = new NetworkCredential("username", "password");
    WebRequest.DefaultWebProxy = proxy;
    

提交回复
热议问题