0

I have created a custom retrieve entity response class for crm2011 so as to serialize the class. The entity response class is derived from OrganizationRequest class. Its as shown below:

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; }
}

Now when i run the code shown below

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;
    }
}

It says that MetadataId which is a required field is missing.The exception thrown is OrganizationServiceFault was caught //Required field 'MetadataId' is missing. How do i create a metadataId for this custom object in this case?

4

2 回答 2

1

查看MSDN 文档以获取OrganizationRequest. 其中一个属性是Parameters,它是请求工作所需的所有数据的集合。

您的 getter 和 setter 应该设置(或检索)该集合中的值。您不能只创建一个私有字段并期望它起作用。;)

作为记录 - CRM SDK 中可用的所有其他请求类都遵循相同的模式 - 它们派生自OrganizationRequest并且额外的属性只是操作所需的快捷方式Parameters

于 2013-07-31T10:08:49.523 回答
0

只是根据你得到的异常猜测,因为我不知道 crm2011。但例外情况是缺少该字段,您拥有的是一个属性。虽然差异可能看起来微不足道,但使用反射时却有很大差异。

您可能需要做的是:

public Guid MetadataId;

并删除您的财产。

于 2013-07-31T10:10:21.927 回答