2011-07-01 41 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

相关问题