WCF Custom Http Proxy Authentication

前端 未结 2 347
独厮守ぢ
独厮守ぢ 2021-01-03 04:29

Is it possible to provide WCF with a custom proxy address and custom credentials?

I\'ve found this answer on stackoverflow: How to set proxy with credentials to gen

2条回答
  •  借酒劲吻你
    2021-01-03 05:12

    If you set the WebRequest.DefaultWebProxy property to a new WebProxy with credentials, WCF will use it for all HTTP requests that it makes. (This will affect all HttpWebRequests used by the application unless explicitly overridden).

    // get this information from the user / config file / etc.
    Uri proxyAddress;
    string userName;
    string password;
    
    // set this before any web requests or WCF calls
    WebRequest.DefaultWebProxy = new WebProxy(proxyAddress)
    {
        Credentials = new NetworkCredential(userName, password),
    };
    

    My blog post on proxy servers contains further details.

提交回复
热议问题