2009-12-11 189 views
0

我有一個小問題,使用基於HTTPS的 基本身份驗證託管的web服務登錄。我嘗試了以下,但它不起作用。這有什麼限制或陷阱嗎?WCF客戶端調用Java Web服務

  var client = new WSClient(); 
      client.ClientCredentials.UserName.UserName = "xxx"; 
      client.ClientCredentials.UserName.Password = "yyy"; 
      client.doIt(); 

客戶端顯示了HTTP 401未經授權的代碼異常,但它並沒有嘗試登錄。 客戶端正在使用WCF並且由Visual Studio 2008生成,服務器正在運行Java Apache CXF。 使用一個網頁瀏覽器...

回答

1

的基本挑戰工作正常,經過一番調查後這樣做的登錄:

var binding = new BasicHttpBinding(); 
binding.Security.Mode=BasicHttpSecurityMode.TransportCredentialOnly; 
binding.Security.Transport.ClientCredentialType=HttpClientCredentialType.Basic; 
var client = new WSClient(binding, new EndpointAddress("http://localhost/myws")); 
client.ClientCredentials.UserName.UserName = "xxx"; 
client.ClientCredentials.UserName.Password = "yyy"; 
client.doIt();