[英]How do i create a metadataId for a custom class derived from OrganizationRequest?
我為crm2011創建了一個自定義檢索實體響應類,以便對該類進行序列化。 實體響應類派生自OrganizationRequest類。 其如下圖所示:
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被抓//必填字段 missing.The異常“MetadataId”缺失。 在這種情況下,如何為該自定義對象創建一個metadataId?
請查閱MSDN文檔中的OrganizationRequest
。 屬性之一是Parameters
,它是請求工作所需的所有數據的集合。
您的getter和setter應該設置(或檢索)該集合中的值。 您不能只是創建一個私有字段並期望它起作用。 ;)
作為記錄-CRM SDK中可用的所有其他請求類都遵循相同的模式-它們是從OrganizationRequest
派生的,而額外的屬性只是操作所需Parameters
快捷方式。
只是根據您得到的異常猜測,因為我不知道crm2011。 但是例外是說缺少該字段,您擁有的是屬性。 盡管這種差異看似微不足道,但使用反射時卻有很大差異。
您可能需要做的是:
public Guid MetadataId;
並刪除您的財產。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.