我有一個WCF服務和一個使用該服務的客戶端。他們使用WSHttpBinding和MTOM消息編碼。客戶端不使用app.config文件,並執行代碼中的所有端點配置。 它在正常的環境中都能很好地工作,但是現在有一些用戶試圖從http代理後面連接到服務。每當他們嘗試連接時,他們都會得到一個407(需要代理身份驗證)警告。通過http代理獲取WSHttpBinding
我設法建立了自己的測試環境,使用虛擬機和連接到代理的專用網絡,因此我可以模擬他們所看到的。 我已經嘗試在app.config中設置system.net useDefaultCredentials屬性,但這似乎沒有任何效果。我檢查了正在發送的數據包,並且它們不包含任何代理驗證標頭。通過代理查看網絡流量,他們確實使用該標題。
我也嘗試了將代理服務器硬編碼到客戶端,但這給出了「無法連接到服務器」異常。檢查數據包,客戶端發送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...