我有一个使用WSHttpBinding和MTOM消息编码的WCF服务和客户端。客户端没有使用app.config文件,在代码中完成了所有终结点配置。在正常环境下,一切都很好,但现在有些用户试图从http代理后面连接到该服务。每当他们尝试连接时,就会收到407(需要代理身份验证)警告。
我已经设置了app.config中的system.net useDefaultCredentials属性,但似乎没有任何效果。我检查了发送的数据包,发现它们不包含任何Proxy-Authentication头。通过代理查看网络流量,可以看到它们确实使用了该头部。
我还尝试将代理服务器硬编码到客户端中,但这会引发“无法连接到服务器”的异常。检查数据包,客户端向代理发送了三个小数据包,其中没有一个是http请求。我不确定它在那里做什么。
我甚至添加了一个消息检查器到客户端,并手动将所需的标头注入请求中,但这并没有显示在标头中。
我已经快要崩溃了,我真的需要一个解决方案。你有什么想法吗?我可能错过了什么,或者有解决方法吗?
这个(带有wsHttpBinding的WCF服务-操作HTTP请求标头)看起来很有前途,但我还是卡住了。
编辑: 这里有一部分代码。
我已经设置了app.config中的system.net useDefaultCredentials属性,但似乎没有任何效果。我检查了发送的数据包,发现它们不包含任何Proxy-Authentication头。通过代理查看网络流量,可以看到它们确实使用了该头部。
我还尝试将代理服务器硬编码到客户端中,但这会引发“无法连接到服务器”的异常。检查数据包,客户端向代理发送了三个小数据包,其中没有一个是http请求。我不确定它在那里做什么。
我甚至添加了一个消息检查器到客户端,并手动将所需的标头注入请求中,但这并没有显示在标头中。
我已经快要崩溃了,我真的需要一个解决方案。你有什么想法吗?我可能错过了什么,或者有解决方法吗?
这个(带有wsHttpBinding的WCF服务-操作HTTP请求标头)看起来很有前途,但我还是卡住了。
编辑: 这里有一部分代码。
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...