2013-11-27 68 views
0

我必須從C#.NET連接到SOAP服務,但該服務只接受帶有HTTP身份驗證頭的請求。使用「全局Http設置」對SOAP進行身份驗證

看來(基於我的谷歌到目前爲止)像通過Http標頭驗證是不是標準的SOAP,但我不能對SOAP服務進行任何更改。

注意:我不是在談論SOAP標題。

我可以設置HTTP認證,並與了SoapUI成功請求如下所示:

Working SoapUI request, using "Username" and "Password" in the Authorisation tab

我可能是錯什麼了SoapUI正在做幕後 - 這是HTTP認證嗎?

我已經將WSDL導入到我的Visual Studio項目中,並且可以嘗試發出請求,但是我得到了「401 - 未經授權(該HTTP請求未經客戶端身份驗證方案'匿名'。)」錯誤當然。

我想調用服務的方式是這樣的一個:

public List<string> GetVinsForUser(string customerId) 
    { 
     var client = new CustomerService.VehicleClient(); 

     // client.HttpHeaders.Add("username", "SomeUser"); 
     // client.HttpHeaders.Add("password", "SomePassword"); 

     var result = client.findCustomerPlusVehicles(customerId); 

     return result.Vehicles.ToList(); 
    } 

所有到目前爲止,我已經看到了相關的文章似乎暗示有沒有簡單的財產喜歡本作的.NET SOAP的實現。

我明白我可以將soap xml數據發佈到手動構建整個webrequest的端點,但我真的不想破解這個!

即使通過擴展/覆蓋生成的客戶端類的行爲,是否有任何方法來啓用這種認證?

+0

看看原片,你會看到的soapUI是如何發送其請求。我認爲它將驗證信息添加到有效負載。 –

+0

是在原始選項卡我看到「授權:基本Y2Ntd .........」 我的問題是你如何添加http基本認證的SOAP請求在默認的.NET SOAP客戶端。 – perfectionist

+0

我不知道究竟是什麼問題,但如果它是一個Web服務,它應該有一個端點,並且如果身份驗證是基本HTTP,那麼爲什麼你不要嘗試將端點地址更改爲[https://用戶名: [email protected]:portXX/demoService](HTTPS://用戶名:[email protected]:portXX/demoService) – patachi

回答

0

,而不是試圖直接修改SOAP頭,只是讓.NET修改標題:

// windows credential 
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("yourUsername", "yourPassword", "yourDomain.com"); 

// you can also try this 
client.ClientCredentials.UserName.UserName = "yourUsername"; 
client.ClientCredentials.UserName.Password = "yourPassword"; 
相關問題