2013-07-31 30 views
0

我已經爲crm2011創建了一個自定義檢索實體響應類,以序列化該類。實體響應類來源於OrganizationRequest類。它如下圖所示:如何爲OrganizationRequest派生的自定義類創建metadataId?

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這是一個必填字段是拋出missing.The例外是OrganizationServiceFault所示的代碼被捕獲//必填字段'MetadataId'丟失。 在這種情況下,我如何爲這個自定義對象創建一個metadataId?

+0

我不認爲這是可能的,因爲CRM服務器不知道你的RetrieveEntityRequest類是什麼。你有沒有看到一個這樣的例子,或者這只是你最好的想法? – Daryl

回答

1

查看MSDN documentationOrganizationRequest。其中一個屬性是Parameters,它是請求工作所需的所有數據的集合。

您的getter和setter應該設置(或檢索)該集合的值。你不能只創建一個私人領域,並期望它的工作。 ;)

爲了記錄 - CRM SDK中可用的所有其他請求類都遵循相同的模式 - 它們來自OrganizationRequest,而額外的屬性只是操縱所需的Parameters的快捷方式。

0

只是基於你的異常猜測,因爲我不知道crm2011。但是例外情況是說該領域缺失,你擁有的是財產。雖然差異可能看起來微不足道,但使用反射時會有很大的差異。

你可能需要做的是:

public Guid MetadataId; 

,並刪除你的財產。

+0

我已經完成了這個工作,而且之後甚至出現了錯誤。 – hmhajir

相關問題