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

관련 문제