且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

与WCF ChannelBase HTTP代理服务器基本身份验证

更新时间:2022-02-27 16:05:31

您遇到的问题是由于的 WCF将使用同一套既为服务认证和上游Web代理服务器认证客户端凭据。由于您的服务需要不同的一对证书的比你的上游Web代理确实,该请求没有被正确验证,并随后被***。

The problem you're experiencing is due to the fact that WCF will use the same set of client credentials both for service authentication and for upstream web proxy authentication. Since your service requires a different pair of credentials than your upstream web proxy does, the request is not being properly authenticated and subsequently gets blocked.

既然你只能指定一组关于 ClientCredentials 类,解决的办法是为设置凭据在较低级别与Web代理服务器来使用,使用的 WebRequest.DefaultWebProxy 属性。

Since you can specify only a single set of credentials on the ClientCredentials class, the solution is to set the credentials to use with the web proxy at a lower level, using the WebRequest.DefaultWebProxy property.

下面是一个例子:

var webProxy = new WebProxy
{
    Address = "http://myproxy:8080",
    Credentials = new NetworkCredential("username", "password")
};

WebRequest.DefaultWebProxy = webProxy;

您应该然后告诉WCF使用刚通过的 WebProxy 类:

You should then tell WCF to use the default proxy that was just configured through the WebProxy class:

<bindings>
    <customBinding>
        <binding name="MyBinding">
            <textMessageEncoding messageVersion="Soap11" />
            <httpTransport authenticationScheme="Basic"
                           useDefaultWebProxy="true" 
                           bypassProxyOnLocal="true"
                           proxyAuthenticationScheme="Basic" />
        </binding>
    </customBinding>
</bindings>

相关资源:


  • 如何在WCF客户端提供的Web代理身份验证凭据专用
  • How to supply dedicated credentials for web proxy authentication in a WCF client