嘗試從Dynamics CRM中檢索systemuser信息我收到一個錯誤2011.下面的代碼工作:錯誤試圖從CRM接收信息時,2011 Webservice的
public List<CrmUser> GetAllCrmUsers()
{
List<CrmUser> CrmUsers = new List<CrmUser>();
using (CrmSdk.OrganizationServiceClient myCrm = new CrmSdk.OrganizationServiceClient("CustomBinding_IOrganizationService1"))
{
try
{
// this will need to be changed... the address to a key in the app.config and the credentials will need to be whatever is correct for the
// end server to hit the CRM WCF service
myCrm.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://devcrm.removed/XRMServices/2011/Organization.svc");
myCrm.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
CrmSdk.ColumnSet colsPrincipal = new CrmSdk.ColumnSet();
colsPrincipal.Columns = new string[] { "lastname", "firstname", "domainname", "systemuserid" };
CrmSdk.QueryExpression queryPrincipal = new CrmSdk.QueryExpression();
queryPrincipal.EntityName = "systemuser";
queryPrincipal.ColumnSet = colsPrincipal;
CrmSdk.EntityCollection myAccounts = myCrm.RetrieveMultiple(queryPrincipal);
foreach (CrmSdk.Entity myEntity in myAccounts.Entities)
{
//create new crm users and add it to the list
CrmUser thisOne = new CrmUser();
thisOne.firstName = myEntity.Attributes[0].Value.ToString();
thisOne.lastName = myEntity.Attributes[1].Value.ToString();
thisOne.userId = myEntity.Attributes[2].Value.ToString();
thisOne.userGuid = myEntity.Attributes[3].Value.ToString();
CrmUsers.Add(thisOne);
}
}
catch (Exception ex)
{
CrmUser thisOne = new CrmUser();
thisOne.firstName = "Crap there was an error";
thisOne.lastName = ex.ToString();
CrmUsers.Add(thisOne);
}
}
return CrmUsers;
}
但是,如果我嘗試添加「businessunitid 「到ColumnSet當我調用該服務的,我得到一個錯誤,指出:
」錯誤在第1行位置1879元\ 2004/07/System.Collections.Generic:值\」包含從類型數據映射到名稱\'/ xrm/2011/Contracts:OptionSetValue \'。反序列化程序不知道映射的任何類型到這個名字。考慮使用DataContractResolver或將與'OptionSetValue'相對應的類型添加到已知類型的列表中 - 例如,通過使用KnownTypeAttribute屬性或將其添加到傳遞給DataContractSerializer的已知類型的列表中。''
此錯誤是因爲根據metadata information正在返回的數據是類型「查找」。我試圖在[Data Contract]
標記下添加[KnownType(typeof(OptionSetValue))]
無效,我已經兩天了谷歌和Binging(?)所以如果它已經被回答道歉
好奇心:您在代碼中使用哪些CRM程序集?來自crm 2011 sdk? CrmUser是一個自定義類? –
是的,CrmUser是一個自定義類,包含4個字符串。名字,姓氏,用戶id,userGuid。我正在使用Microsoft.Xrm.Sdk程序集版本5.0.0.0。 – EricKitt
你可以請指定你的應用程序的類型(silverlight,windows窗體,web服務),如果silverlight如果運行在web內部crm或不是 –