Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过代理(使用用户名/密码)连接到WCF服务(.svc)_C#_Wcf_Wcf Security - Fatal编程技术网

C# 通过代理(使用用户名/密码)连接到WCF服务(.svc)

C# 通过代理(使用用户名/密码)连接到WCF服务(.svc),c#,wcf,wcf-security,C#,Wcf,Wcf Security,我已经创建了一个WCF服务。我这样称呼它: ServiceClient client = new ServiceClient (); client.MyMethod(); 到目前为止,我的机器还不错 现在我已经在我们的DMZ中部署了它,我可以通过一个外部URL调用它,这样来自我的机器的请求就可以发送到Internet,然后发送到我们的数据中心 但是,我们通过代理连接到互联网。我不确定这是如何工作的,但如果我想访问StackOverflow站点,我必须在InternetExplorer的连接、L

我已经创建了一个WCF服务。我这样称呼它:

ServiceClient client = new ServiceClient ();
client.MyMethod();
到目前为止,我的机器还不错

现在我已经在我们的DMZ中部署了它,我可以通过一个外部URL调用它,这样来自我的机器的请求就可以发送到Internet,然后发送到我们的数据中心

但是,我们通过代理连接到互联网。我不确定这是如何工作的,但如果我想访问StackOverflow站点,我必须在InternetExplorer的连接、LAN设置部分输入代理服务器

当我不更改代码时,会出现以下错误:

远程服务器返回了一个错误消息 意外响应:407代理 ISA需要身份验证 服务器需要授权才能运行 满足要求。上网 代理筛选器被拒绝

在谷歌搜索之后,我发现了这个代码,但它给我留下了同样的错误

  var b = client.Endpoint.Binding as System.ServiceModel.WSHttpBinding;
            b.ProxyAddress = new Uri("http://OURADDRESS.intern:8080");     
            b.BypassProxyOnLocal = false;     
            b.UseDefaultWebProxy = false;
            client.ClientCredentials.UserName.UserName = @"DOMAIN\USERNAME";
            client.ClientCredentials.UserName.Password = "myverysecretpassword";

在这种情况下,使用默认代理就足够了:

<configuration>
  <system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>
  ...
</configuration>
如果手动设置凭据,我相信您的代理需要Windows凭据,因此应使用:

client.ClientCredentials.Windows.ClientCredential.UserName = @"DOMAIN\USERNAME";
client.ClientCredentials.Windows.ClientCredential.Password = "myverysecretpassword";

您是否可以尝试使用UseDefaultWebProxy=true并且不设置ClientCredentials。这应该使用IE中的代理设置。这给了我相同的例外。您应该首先询问管理员代理需要什么类型的身份验证。错误:服务未对调用方进行身份验证。没有凭据错误:安全支持提供程序接口SSPI协商失败。对于CredentialFillder说:由于身份验证失败,无法满足对安全令牌的请求。
client.ClientCredentials.Windows.ClientCredential.UserName = @"DOMAIN\USERNAME";
client.ClientCredentials.Windows.ClientCredential.Password = "myverysecretpassword";