C# 如何为从OrganizationRequest派生的自定义类创建metadataId?
我为crm2011创建了一个自定义检索实体响应类,以便序列化该类。实体响应类派生自OrganizationRequest类。其功能如下所示:C# 如何为从OrganizationRequest派生的自定义类创建metadataId?,c#,dynamics-crm-2011,C#,Dynamics Crm 2011,我为crm2011创建了一个自定义检索实体响应类,以便序列化该类。实体响应类派生自OrganizationRequest类。其功能如下所示: public partial class RetrieveEntityRequest : OrganizationRequest { public RetrieveEntityRequest() { } private System.Guid metadataIdField; public System.Guid
public partial class RetrieveEntityRequest : OrganizationRequest
{
public RetrieveEntityRequest()
{
}
private System.Guid metadataIdField;
public System.Guid MetadataId
{
get
{
return this.metadataIdField;
}
set
{
this.metadataIdField = value;
}
}
public EntityFilters EntityFilters { get; set; }
public string LogicalName { get; set; }
public bool RetrieveAsIfPublished { get; set; }
}
现在,当我运行下面显示的代码时
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
try
{
serviceProxy.EnableProxyTypes();
request = new CrmUtilities.RetrieveEntityRequest();
request.LogicalName=entityName;
request.EntityFilters = EntityFilters.Entity;
request.RequestName = requestName;
//Execute Request
retrieveEntityResponse = (CrmUtilities.RetrieveEntityResponse)serviceProxy.Execute(request);
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
它表示缺少必需字段MetadataId。引发的异常为OrganizationServiceFault已捕获//缺少必需字段“MetadataId”。
在这种情况下,如何为此自定义对象创建元数据ID?请查看for组织请求。其中一个属性是参数
,它是请求工作所需的所有数据的集合
getter和setter应该设置(或检索)该集合中的值。您不能只创建一个私有字段,然后期望它工作。;)
作为记录-CRM SDK中可用的所有其他请求类都遵循相同的模式-它们派生自OrganizationRequest
,额外的属性只是操作所需参数的快捷方式,因为我不知道crm2011,只需根据您得到的异常进行猜测即可。但例外情况是缺少字段,您拥有的是一个属性。虽然差异看起来微不足道,但使用反射时却有很大的差异
您可能需要做的是:
public Guid MetadataId;
并移除你的财产 我已经这样做了,即使在那之后错误仍然存在。我认为这是不可能的,因为CRM服务器不知道您的RetrieveEntityRequest类是什么。你有没有看到这样的例子,或者这只是你最好的主意?