我創建了一個WCF服務。我這樣稱呼它:通過代理(使用用戶名/密碼)連接到WCF服務(.svc)
ServiceClient client = new ServiceClient();
client.MyMethod();
到目前爲止我的機器上很好。
現在我已經將它部署在我們的DMZ中(無論那是什麼),並且我可以通過外部URL調用它(所以來自我的機器的請求發送到Internet,然後發送到我們的數據中心)。
但是,我們通過代理連接到Internet。我不知道這是如何工作的,但我必須在互聯網 Explorer的連接,局域網設置部分輸入代理服務器,如果我想訪問堆棧 溢出網站。
當我不改變的代碼,我得到這個錯誤:
The remote server returned an unexpected response: (407) Proxy Authentication Required (The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ).
谷歌搜索後,我發現這個代碼,但它給我留下了同樣的錯誤。
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";
您可以使用UseDefaultWebProxy = true來嘗試並且不設置ClientCredentials。這應該使用IE的代理設置。 – 2011-06-17 08:50:01
給了我同樣的例外 – Michel 2011-06-17 08:56:53
您應該首先詢問您的管理員您的代理需要哪種類型的身份驗證。 – 2011-06-17 10:27:03