В настоящее время я создаю службу .net С#, которая использует вызов веб-службы для отправки информации из 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». Заголовок аутентификации, полученный от сервера, был «Basic realm = «Upload Protected Area»». ---> System.Net.WebException: Удаленный сервер вернул ошибку: (401) Несанкционировано. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- Конец внутренней трассировки стека исключений ---
Любая помощь в решении этой проблемы и, если возможно, в ее динамичности, очень ценится.
Заранее благодарю.