1

我使用通道工厂创建了一个 WCF 客户端。但我无法连接到另一台机器上的服务器。我收到 (407) 需要 Proxy Authentication 异常。

WSHttpBinding wsBinding = new WSHttpBinding();
        wsBinding.BypassProxyOnLocal = true;

        EndpointAddress endpoint =
          new EndpointAddress("http://machineName:7676/MyWCFService");
        ChannelFactory<IService> sericeInterface =
            new ChannelFactory<IService>(wsBinding, endpoint);

        sericeInterface.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
        sericeInterface = sericeInterface.CreateChannel();

这是我的客户端连接代码片段。当我调用服务的方法时出现异常。

4

1 回答 1

1

看看这个CodePlex链接,试着找到一个与你的场景非常匹配的场景。它提供了有关如何为不同情况/绑定设置各种凭据的清单和示例。

此外,此MSDN 链接可能有助于您似乎正在使用的 Windows 身份验证。

要分配凭据,您需要类似于以下从 MSDN 链接获取的内容:

CalculatorClient cc = new 
    CalculatorClient("WSHttpBinding_ICalculator");
// This code returns the WindowsClientCredential type.            
cc.ClientCredentials.Windows.ClientCredential.UserName = GetUserName();
cc.ClientCredentials.Windows.ClientCredential.Password = GetPassword();
于 2009-12-04T09:57:22.723 回答