2011-07-01 67 views
3

我有一個需要從Activity實體獲取OptionSetValue屬性標籤的Silverlight應用程序。屬性邏輯名稱是activitytypecode,我有以下的擴展方法來檢索屬性的元數據:通過CRM 2011中的SOAP服務獲取OptionSetValue的標籤

public static void RetrieveAttribute(this IOrganizationService service, 
     string entityLogicalName, string entityAttributeName, 
     Action<OrganizationResponse> callback) 
    {    
     var retrieveAttributeRequest = new OrganizationRequest() 
     { 
      RequestName = "RetrieveAttribute", 
     }; 

     retrieveAttributeRequest["EntityLogicalName"] = entityLogicalName; 
     retrieveAttributeRequest["RetrieveAsIfPublished "] = false; 
     retrieveAttributeRequest["LogicalName"] = entityAttributeName; 

     service.BeginExecute(retrieveAttributeRequest, 
      result => 
      { 
       if (result.IsCompleted) 
       { 
        var response = service.EndExecute(result); 

        callback(response); 
       } 
      }, null); 
    } 

,我用我的SoapCtx已經被初始化如下:

SoapCtx.RetrieveAttribute("activitypointer", "activitytypecode", 
    orgResponse => 
    { 
     if (orgResponse != null) 
     { 
      // examine orgResponse 
     } 
    }); 

我能夠調試過程,但它在線路上失敗var response = service.EndExecute(result);在我的擴展方法。我得到以下異常消息:

The remote server returned an error: NotFound.

這裏的堆棧跟蹤,如果你會發現它有用:

{System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. 
    at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 
    at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState) 
    at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState) 

我明白任何幫助或指導,謝謝!

回答

2

除了匿名方法,以下爲我工作。 請注意MetadataId

private void StartGetAttributeMetadata() 
    { 
     OrganizationRequest request = new OrganizationRequest() { RequestName = "RetrieveAttribute" }; 
     request["EntityLogicalName"] = "activitypointer"; 
     request["LogicalName"] = "activitytypecode"; 
     request["MetadataId"] = Guid.Empty; 
     request["RetrieveAsIfPublished"] = true; 

     IOrganizationService service = SOAPServerUtility.GetSoapService(); 
     service.BeginExecute(request, new AsyncCallback(EndGetAttributeMetadata), service); 
    } 

    private void EndGetAttributeMetadata(IAsyncResult result) 
    { 
     OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result); 
    } 
+0

非常感謝,做這種方式爲我工作。我沒有嘗試這種方式,因爲我認爲這將是無關緊要的,因爲他們都做同樣的事情,除了以不同的方式。它很臭,我不能使用匿名方法,並且我不知道爲什麼SOAP環境在這樣完成時變得不合時宜。我現在沒有選擇,只能爲每個請求寫一堆單獨的事件處理程序,我討厭這樣做,因爲它會讓你的代碼更難讀。再次,非常感謝,這讓我瘋狂了好幾個小時。 – Jose

相關問題