我對整個 WCF 和 SOAP 主題有點陌生,所以請善待。
我正在使用.net6 生成的 SOAP 客戶端。在另一個專案中,我們使用舊的 .net Framework 2.0 Web 參考和相同的憑據成功地使用了相同的 Web 服務。
奇怪的是,起初一切似乎都很好。直到我意識到,它不使用給定的憑據進行身份驗證。相反,它使用我自己的域用戶進行身份驗證。我還嘗試讓它與顯式設定系結一起作業,BasicHttpBinding但我只能讓相同的損壞邏輯作業,或者我遇到各種身份驗證/協議/安全錯誤。
所以看起來身份驗證基本上是有效的。它只是不使用提供的憑據。所以我的問題是:如何配置它以使用提供的身份?
我還發現它可能與快取的 Windows 令牌有關。但我怎么能擺脫它。首先如何防止快取?
編輯:明確指定變數型別。
string url = "http://someServer/AdministrationService.asmx";
AdministrationServiceSoapClient client = new AdministrationServiceSoapClient(
AdministrationServiceSoapClient.EndpointConfiguration.AdministrationServiceSoap,
url);
WindowsClientCredential credential = client.ClientCredentials.Windows;
credential.ClientCredential.UserName = "username";
credential.ClientCredential.Password = "password";
credential.ClientCredential.Domain = "DOMAIN";
GetServerInfoRequest getServerInfoRequest = new GetServerInfoRequest
{
// some stuff set here
};
GetServerInfoRequest getServerInfoReply = await client.GetServerInfoAsync(getServerInfoRequest);
uj5u.com熱心網友回復:
據我所知,BasicHttpBinding 默認禁用安全性,但可以在建構式中將 BasicHttpSecurityMode 設定為 None 以外的值。可以根據BasicHttpBinding和BasicHttpBinding Constructors中的說明進行配置。
默認情況下,設定客戶端憑據包括兩個步驟:確定服務所需的客戶端憑據型別和指定實際客戶端憑據,如本檔案中所述。
uj5u.com熱心網友回復:
等待一天后,它正在作業。似乎快取的憑據以某種方式變得無效。
奇怪的是,上面的簡單服務創建不再起作用了。相反,我必須使用以下內容。
var client = new AdministrationServiceSoapClient(
new BasicHttpBinding()
{
Security = new BasicHttpSecurity()
{
Mode = BasicHttpSecurityMode.TransportCredentialOnly,
Message = new BasicHttpMessageSecurity()
{
ClientCredentialType = BasicHttpMessageCredentialType.UserName,
},
Transport = new HttpTransportSecurity()
{
ClientCredentialType = HttpClientCredentialType.Windows,
ProxyCredentialType = HttpProxyCredentialType.Windows,
}
},
},
new EndpointAddress(url));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/512560.html
