【发布时间】:2012-06-05 22:44:49
【问题描述】:
我有一个 WCF 服务和一个使用该服务的客户端。他们使用 WSHttpBinding 和 MTOM 消息编码。客户端不使用 app.config 文件,而是在代码中完成所有端点配置。 这一切在正常环境中运行得相当好,但是我现在有一些用户试图从 http 代理后面连接到服务。每当他们尝试连接时,都会收到 407(需要代理身份验证)警告。
我已经设法使用带有连接到代理的专用网络的虚拟机设置了自己的测试环境,因此我可以模拟他们所看到的内容。 我尝试在 app.config 中设置 system.net useDefaultCredentials 属性,但这似乎没有任何效果。我检查了正在发送的数据包,它们不包含任何 Proxy-Authentication 标头。通过代理查看网络流量,他们确实使用了该标头。
我还尝试将代理服务器硬编码到客户端中,但这会导致“无法连接到服务器”异常。检查数据包,客户端向代理发送了 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...
【问题讨论】:
标签: c# wcf proxy wshttpbinding