2011-05-20 99 views
2

嘗試連接到CRM 2011 Web服務時發生意外錯誤。這裏的背景:CRM 2011 SecurityNewiationException嘗試訪問Web服務

連接字符串(敏感信息已刪除):"ServiceUri=https://crmdomain.com/OrgName/XRMServices/2011/Organization.svc; Url=https://crmdomain.com/OrgName; Username=appusername; Password=hidden"/>

創建連接如下:

  1. 解析康恩串入CRMConnection:var conn = Microsoft.Xrm.Client.CrmConnection.Parse(connString);(在這一點上,屬性在CrmConnection對象外觀正確,包括ClientCredentials)
  2. 創建組織代理:var orgProxy = new OrganizationServiceProxy(conn.ServiceUri, conn.HomeRealmUri, conn.ClientCredentials, conn.DeviceCredentials);
  3. 創建數據上下文:var context = new MyContext(orgProxy);

此時,從context檢索的任何數據時,會出現以下WCF異常:

System.ServiceModel.Security.SecurityNegotiationException發生 消息= 的呼叫者未被該服務認證。 源= mscorlib程序 堆棧跟蹤: 服務器堆棧跟蹤: 在System.ServiceModel.Security.IssuanceTokenProviderBase'1.DoNegotiation(時間跨度超時) 在System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(時間跨度超時) 在System.ServiceModel .Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan超時)

...等等。

The InnerException顯示IsSenderFault=TrueIsPredefinedFault=True

這是怎麼回事?

+0

如果您使用ServerConnection助手類來構建連接字符串,這仍會失敗嗎? – Josh 2011-05-20 16:34:28

回答

0

您可能想通過使用CRM跟蹤來縮小CRM中的確切錯誤。您可以使用dedicated tool激活CRM跟蹤,並搜索該跟蹤以獲取有關異常來源的更多詳細信息。請注意,跟蹤文件速度非常快,因此僅在web服務調用期間跟蹤纔是合理的。

0

我找到了解決方案。首先,請下載CRM SDK的發佈RTW 2011年

代碼連接將是:

public static IOrganizationService Service() 
{ 
    ClientCredentials Credentials = new ClientCredentials(); 
    Credentials.Windows.ClientCredential.UserName ="<username>"; 
    Credentials.Windows.ClientCredential.Password ="<password>"; 

    //This URL needs to be updated to match the servername and Organization for the environment. 
    Uri OrganizationUri = new Uri("http://<server name>/<organization name>/XRMServices/2011/Organization.svc"); 
    Uri HomeRealmUri = null; 

    //OrganizationServiceProxy serviceProxy; 
    using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)) 
    { 
     IOrganizationService service = (IOrganizationService)serviceProxy; 
     return service; 
    } 
} 

,在這裏你去...

乾杯!享受編碼。