WCF Custom Http Proxy Authentication

前端 未结 2 348
独厮守ぢ
独厮守ぢ 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.

    0 讨论(0)
  • 2021-01-03 05:28

    The client credentials you're setting are fine in order to authenticate to your services.
    For proxy authentication you need to use HttpTransportSecurity.ProxyCredentials.

    This link might help you out.

    http://msdn.microsoft.com/en-us/library/system.servicemodel.httptransportsecurity.proxycredentialtype.aspx

    0 讨论(0)
提交回复
热议问题