[英]Consuming a web service using digest authentication
我們正在使用C#通過SOAP發送XML數據。 該服務需要具有#PasswordDigest
和#Base64Binary Nonce
#PasswordDigest
#Base64Binary Nonce
HttpDigest身份驗證。 我們的binding
代碼:
protected BasicHttpBinding binding = new BasicHttpBinding()
{
Name = "ShipmentServiceSoapBinding",
CloseTimeout = new TimeSpan(0, 01, 0),
OpenTimeout = new TimeSpan(0, 01, 0),
ReceiveTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 5, 0),
AllowCookies = false,
BypassProxyOnLocal = false,
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
MaxBufferPoolSize = 5242880,
MaxReceivedMessageSize = 655360,
MessageEncoding = WSMessageEncoding.Text ,
TextEncoding = new UTF8Encoding(),
UseDefaultWebProxy = true,
ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxDepth = 32, MaxStringContentLength = 81920, MaxArrayLength = 1638400, MaxBytesPerRead = 409600, MaxNameTableCharCount = 163840 },
Security = new BasicHttpSecurity() { Mode = BasicHttpSecurityMode.TransportWithMessageCredential,
//Message = new BasicHttpMessageSecurity() { AlgorithmSuite = SecurityAlgorithmSuite.Default, ClientCredentialType = BasicHttpMessageCredentialType.UserName},
Transport = new HttpTransportSecurity(){ ClientCredentialType = HttpClientCredentialType.Digest}},
};
根據我們選擇的BasicHttpSecurityMode類型,我們遇到3個不同的問題。
現在,他們的ServiceReference允許我們使用ClientCredentials類,因此這是我們嘗試使用HttpDigest的方式:
typeClient.ClientCredentials.HttpDigest.ClientCredential.UserName = "username";
typeClient.ClientCredentials.HttpDigest.ClientCredential.Password = "password";
我已經閱讀了其他StackOverflow問題,對於摘要,我們應該將SoapHeader與AuthHeader一起使用,但是我們無法將其與API中提供的內容進行匹配。 還有其他方法嗎? 還是他們的API沒有為C#正確編寫?
在這種情況下,使用摘要身份驗證要復雜得多-您將需要實現IClientMessageInspector
才能使其正常工作...這使您能夠以摘要身份驗證所需的方式修改http標頭。
有用的網址:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.