尝试从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或不是 –