簡體   English   中英

調用 SAP PI Web 服務時,HTTP 請求未經客戶端身份驗證方案“Ntlm”授權

[英]The HTTP request is unauthorized with client authentication scheme 'Ntlm' while calling SAP PI web service

我目前正在創建一個 .net C# 服務,它使用 webservice 調用將信息從 CRM 2011 發送到 SAP。

憑證如下:

((BasicHttpBinding)defaultBinding).Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
((BasicHttpBinding)defaultBinding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; //.Ntlm;

PropertyInfo piClientCreds = type.GetProperty("ClientCredentials");
ClientCredentials creds = (ClientCredentials)piClientCreds.GetValue(obj, null);
PropertyInfo piWindowsCreds = creds.GetType().GetProperty("Windows");
WindowsClientCredential windowsCreds = (WindowsClientCredential)piWindowsCreds.GetValue(creds, null);
PropertyInfo piAllowNtlm = windowsCreds.GetType().GetProperty("AllowNtlm");
piAllowNtlm.SetValue(windowsCreds, true, null);
PropertyInfo piCredentials = windowsCreds.GetType().GetProperty("ClientCredential");
piCredentials.SetValue(windowsCreds, credentials, null);
PropertyInfo piImpersonation = windowsCreds.GetType().GetProperty("AllowedImpersonationLevel");
piImpersonation.SetValue(windowsCreds, System.Security.Principal.TokenImpersonationLevel.Impersonation, null);

我得到的錯誤是:

{System.ServiceModel.Security.MessageSecurityException:HTTP 請求未經客戶端身份驗證方案“Ntlm”授權。 從服務器收到的身份驗證標頭是“基本領域=“上傳保護區””。 ---> System.Net.WebException:遠程服務器返回錯誤:(401) 未經授權。 在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- 內部異常堆棧跟蹤結束---

非常感謝解決此問題的任何幫助,並在可能的情況下使其動態化。

先謝謝了。

問題很明顯。 服務器希望您的客戶端使用基本身份驗證,而您的客戶端嘗試使用 NTLM 進行身份驗證。 嘗試使用UserNamePasswordClientCredential 進行身份驗證。 您應該僅通過安全傳輸(例如 HTTPS)執行此操作。

暫無
暫無

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

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