[英]The HTTP request is unauthorized with client authentication scheme 'Ntlm' while calling SAP PI web service
I am currently creating a .net C# service which uses webservice invoking to send information from CRM 2011 to SAP.我目前正在创建一个 .net C# 服务,它使用 webservice 调用将信息从 CRM 2011 发送到 SAP。
The credentials are said as following:凭证如下:
((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);
The error I get is:我得到的错误是:
{System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Ntlm'.
{System.ServiceModel.Security.MessageSecurityException:HTTP 请求未经客户端身份验证方案“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.
---> System.Net.WebException:远程服务器返回错误:(401) 未经授权。 at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace ---
在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- 内部异常堆栈跟踪结束---
Any help in resolving this and if possible making it dynamic is much appreciated.非常感谢解决此问题的任何帮助,并在可能的情况下使其动态化。
Thank you in advanced.先谢谢了。
The problem is quite obvious.问题很明显。 The server expects the your client to use Basic authentication while your client attempts to authenticate using NTLM.
服务器希望您的客户端使用基本身份验证,而您的客户端尝试使用 NTLM 进行身份验证。 Try authenticating using UserNamePasswordClientCredential .
尝试使用UserNamePasswordClientCredential 进行身份验证。 You should do this only over a secure transport such as HTTPS.
您应该仅通过安全传输(例如 HTTPS)执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.