我有一个WCF服务和一个使用该服务的客户端。他们使用带有MTOM消息编码的WSHttpBinding。客户端不使用app.config文件,所有端点配置都是在代码中完成的。这一切在正常的环境中都运行得相当好,但是我现在有一些用户试图从http代理后面连接到该服务。无论何时尝试连接,都会收到407 (需要代理身份验证)警告。
我已经设法使用具有连接到代理的私有网络的虚拟机设置了我自己的测试环境,这样我就可以模拟他们所看到的。我尝试在app.config中设置system.net useDefaultCredentials属性,但似乎没有任何效果。我已经检查了正在发送的数据包,它们不包含任何代理身份验证头。查看通过代理的web流量时,它们确实使用了该报头。
我也尝试过将代理服务器硬编码到客户端,但这给出了一个“无法连接到服务器”的异常。检查数据包时,客户端向代理发送了3个小数据包,其中没有一个是http请求,仅此而已。我不知道它在那里做什么。
我甚至还向客户端添加了一个消息检查器,并手动将所需的头注入到请求中,但这并没有显示在头中。
我已经走到尽头了,我真的需要一个解决方案。有没有什么好的想法或者解决方案?
这个( WCF Service with wsHttpBinding - Manipulating HTTP request headers )似乎很有前途,但我还是卡住了。
编辑:这是代码的一部分。
var binding = new WSHttpBinding();
binding.MaxReceivedMessageSize = 100000000;
binding.MessageEncoding = WSMessageEncoding.Mtom;
binding.ReaderQuotas.MaxArrayLength = 100000000;
binding.OpenTimeout = new TimeSpan(0, 2, 0);
binding.ReceiveTimeout = new TimeSpan(0, 2, 0);
binding.SendTimeout = new TimeSpan(0, 2, 0);
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.UseDefaultWebProxy = true;
// I've also tried setting this to false, and manually specifying the binding.ProxyAddress
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
var endpointAddress = new EndpointAddress(new Uri(hostUrl));
clientProxy_ = new UpdaterServiceProxy(binding, endpointAddress);
// this behavior was the attempt to manually add the Proxy-Authentication header
//clientProxy_.Endpoint.Behaviors.Add(new MyEndpointBehavior());
clientProxy_.ClientCredentials.UserName.UserName = userName;
clientProxy_.ClientCredentials.UserName.Password = password;
clientProxy_.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
System.ServiceModel.Security.X509CertificateValidationMode.ChainTrust;
// do stuff...发布于 2012-06-09 01:16:28
经过大量的实验,我取得了一些进展。事实证明,我可以手动指定代理,它将工作。
WebProxy proxy = new WebProxy("http://x.x.x.x:3128", false);
proxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = proxy;这段代码出现在我实例化我的clientProxy_之前。我之前已经尝试过了,但由于我没有指定端口,它无声无息地失败了。我仍然无法让它获取在Windows Internet设置中指定的代理设置。我尝试设置proxy.Credentials = CredentialCache.DefaultNetworkCredentials;,但似乎也没有效果。
我现在还遇到了一个问题,客户端试图使用ChainTrust验证服务的证书,但对链接证书的请求没有使用代理设置。因为这是一个更具体的问题,所以我在这里单独写下了它:Certificate validation doesn't use proxy settings for chaintrust
所以我还是希望能得到更多的帮助。
更新:我只是在我的应用程序中添加了一个网络配置对话框,这样用户就可以指定他们的代理设置。我无法让自动代理设置正常工作。
https://stackoverflow.com/questions/10906054
复制相似问题