通过CRM 2011中的SOAP服务获取OptionSetValue的标签

时间:2011-07-01 17:50:47

标签: silverlight dynamics-crm-2011

我有一个Silverlight应用程序需要从Activity实体获取OptionSetValue属性的标签。属性逻辑名称是 activitytypecode ,我有以下扩展方法来检索属性元数据:

    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); 行失败。我收到以下异常消息:

  

远程服务器返回错误:NotFound。

如果你发现它很有用,那么这就是StackTrace:

{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)

感谢任何帮助或指导,谢谢!

1 个答案:

答案 0 :(得分: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);
    }