2013-10-21 104 views
0

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

憑據表示如下:

((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 ---

解決這一點,如果可能使其動態任何幫助深表感謝。

謝謝您的高級。

回答

1

問題很明顯。服務器期望您的客戶端在您的客戶端嘗試使用NTLM進行身份驗證時使用基本身份驗證。嘗試使用UserNamePasswordClientCredential進行身份驗證。您只能通過安全傳輸(如HTTPS)執行此操作。

+0

感謝您的快速回復。你能否幫我把這個網站的財產翻譯成正確的格式? –