簡體   English   中英

使用摘要身份驗證消耗Web服務

[英]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個不同的問題。

  1. 傳輸-XML不包含任何安全信息
  2. TransportCredentialOnly-我們收到的錯誤指出端點不能為https://
  3. TransportWithMessagecredential-這不使用摘要

現在,他們的ServiceReference允許我們使用ClientCredentials類,因此這是我們嘗試使用HttpDigest的方式:

typeClient.ClientCredentials.HttpDigest.ClientCredential.UserName = "username";
typeClient.ClientCredentials.HttpDigest.ClientCredential.Password = "password";

我已經閱讀了其他StackOverflow問題,對於摘要,我們應該將SoapHeader與AuthHeader一起使用,但是我們無法將其與API中提供的內容進行匹配。 還有其他方法嗎? 還是他們的API沒有為C#正確編寫?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM