2012-03-13 112 views
0

我們使用C#通過SOAP發送XML數據。該服務需要使用#PasswordDigest#Base64Binary Nonce進行HttpDigest身份驗證。我們binding代碼:使用摘要式身份驗證來使用Web服務

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的錯誤: - 這可不是用消化
//
  • TransportWithMessagecredential

    現在,他們的服務引用允許我們使用ClientCredentials類,所以這裏是我們如何嘗試使用HttpDigest:

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

    我讀過其他StackOverflow問題,對於摘要,我們應該使用帶有AuthHeader的SoapHeader,但是我們沒有辦法讓它與它給出的API匹配。還有其他的方式嗎?或者他們的API不能正確寫入C#?

  • 回答

    相關問題