当调用SAP PI网络服务时,HTTP请求未经授权,客户端认证方案为 "Ntlm"。

问题描述 投票:0回答:1

我目前正在创建一个.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:

{System.ServiceModel.Security.MessageSecurityException: HTTP请求未经授权,客户端认证方案为'Ntlm'。从服务器接收到的认证头是'Basic realm="Upload Protected Area"'。---> System.Net.WebException: 远程服务器返回一个错误。在System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) ---内部异常堆栈跟踪结束 ---

任何帮助解决这个问题,如果可能的话,使其动态是非常感激的。

先谢谢你。

c# web-services sap sap-xi sap-pi
1个回答
1
投票

问题很明显。服务器希望你的客户端使用Basic认证,而你的客户端试图使用NTLM认证。请尝试使用 用户名密码客户端密码. 你应该只通过安全的传输,如HTTPS。

© www.soinside.com 2019 - 2024. All rights reserved.