2011-06-17 98 views
2

我創建了一個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"; 
+0

您可以使用UseDefaultWebProxy = true來嘗試並且不設置ClientCredentials。這應該使用IE的代理設置。 – 2011-06-17 08:50:01

+0

給了我同樣的例外 – Michel 2011-06-17 08:56:53

+0

您應該首先詢問您的管理員您的代理需要哪種類型的身份驗證。 – 2011-06-17 10:27:03

回答

5

在這種情況下,使用默認的代理應該足夠:

<configuration> 
    <system.net> 
    <defaultProxy useDefaultCredentials="true" /> 
    </system.net> 
    ... 
</configuration> 

在你的綁定,你只能保證使用默認代理(應該是默認啓用):

b.UseDefaultWebProxy = true; 

在手動設置憑據的情況下,我相信您的代理需要Windows憑據,因此應該使用這種方式:

client.ClientCredentials.Windows.ClientCredential.UserName = @"DOMAIN\USERNAME"; 
client.ClientCredentials.Windows.ClientCredential.Password = "myverysecretpassword"; 
+0

錯誤:調用者未被服務認證。 (沒有憑據) – Michel 2011-06-17 09:11:41

+0

錯誤:安全支持提供程序接口(SSPI)協商失敗。 (使用憑證) – Michel 2011-06-17 09:11:58

+0

fillder說:由於身份驗證失敗,無法滿足安全令牌請求。 – Michel 2011-06-17 09:13:07

相關問題