调用 SAP PI Web 服务时,客户端身份验证方案“Ntlm”对 HTTP 请求是未经授权的

本文关键字:请求 HTTP 授权 Ntlm 服务 Web PI SAP 方案 身份验证 客户端 | 更新日期: 2023-09-27 18:36:09

我目前正在创建一个.NET C#服务,该服务使用Web服务调用将信息从CRM 2011发送到SAP PI。

凭据说明如下:

((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: The HTTP request is
   unauthorized with client authentication scheme 'Ntlm'. The authentication header
   received from the server was 'Basic realm="Upload Protected Area"'.
---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

非常感谢任何解决此问题的帮助,如果可能的话,使其动态化。

提前谢谢你。

调用 SAP PI Web 服务时,客户端身份验证方案“Ntlm”对 HTTP 请求是未经授权的

问题很明显。服务器希望客户端使用基本身份验证,而客户端尝试使用 NTLM 进行身份验证。尝试使用 UserNamePasswordClientCredential 进行身份验证。应仅通过安全传输(如 HTTPS)执行此操作。