2016-09-26 2 views
0

저는 Flex 초보자이며 WebAPI 서비스에서 정보를 받아 표시하는 MXML 응용 프로그램을 작성하고 있습니다.WebAPI에서 Flex로 객체 반환

지금까지 간단한 문자열로이를 처리했지만 복잡한 객체를 반환하려고하면 null을 반환합니다.

여기 그것은 매우 간단한 형태의, 내 코드입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:acrs_surveys="services.acrs_surveys.*" 
    xmlns:valueObjects="valueObjects.*" 
    minWidth="955" minHeight="600"> 
    <s:layout> 
     <s:VerticalLayout/> 
     </s:layout> 
    <fx:Script> 
     <![CDATA[ 
      import mx.controls.Alert; 
      import mx.rpc.events.ResultEvent; 

      protected function button_clickHandler(event:MouseEvent):void 
      { 
       GetSurveyResult.token = acrs_surveys.GetSurvey(itemidTextInput.text); 
      } 

      protected function button2_clickHandler(event:MouseEvent):void 
      { 
       survey.SurveyId = surveyIdTextInput.text; 
       survey.Title = titleTextInput.text; 
      } 

      protected function assignSurveyResult(event:ResultEvent):void 
      { 
       survey = event.result as Survey; 
      } 
     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <s:CallResponder id="GetSurveyResult" result="assignSurveyResult(event)"/> 
     <valueObjects:Survey id="survey"/> 
     <acrs_surveys:Acrs_surveys id="acrs_surveys" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true" /> 
    </fx:Declarations> 
    <s:Form defaultButton="{button}"> 
     <s:FormItem label="Itemid"> 
      <s:TextInput id="itemidTextInput"/> 
     </s:FormItem> 
     <s:Button id="button" label="GetSurvey" click="button_clickHandler(event)"/> 
    </s:Form> 
    <s:Form defaultButton="{button2}"> 
     <s:FormHeading label="Survey"/> 
     <s:FormItem label="Questions"> 
      <s:Label id="QuestionsLabel" text="Questions_type[]"/> 
     </s:FormItem> 
     <s:FormItem label="SurveyId"> 
      <s:TextInput id="surveyIdTextInput" text="{survey.SurveyId}"/> 
     </s:FormItem> 
     <s:FormItem label="Title"> 
      <s:TextInput id="titleTextInput" text="{survey.Title}"/> 
     </s:FormItem> 
     <s:Button id="button2" label="Submit" click="button2_clickHandler(event)"/> 
    </s:Form> 
</s:Application> 

코드는 대부분 플래시 빌더의 마법사에 의해 생성되었습니다. "Survey"클래스는 Generate Service Call 마법사에 의해 생성되었으며 동일한 마법사에 의해 정의 된 GUID, Title 및 Question 개체 목록의 세 가지 속성을 포함합니다.

코드를 실행하면 오류가 발생하지 않고 네트워크 모니터에 따라 호출이 성공적으로 완료되고 데이터가 반환됩니다. 그러나 assignSurveyResult에서 코드를 해독하고 측량 객체를 검사하면 결과가 null입니다.

설문 제목 만 문자열로 반환하는 WebAPI 호출을 사용하도록 코드를 변경하면 올바르게 작동합니다. 그것은 작동하지 않는 객체 들인 것처럼 보입니다.

내가 뭘 잘못하고 있니?

답변

0

플렉스 소스 코드를 추적 한 후 해결책을 찾았습니다. Flash Builder에서 생성 한 클라이언트 프록시 코드가 내 XML 데이터를 JSON으로 역 직렬화하도록 설정했기 때문에 직렬화되지 않은 데이터가 객체로 변환 될 수없는 "http://www.w3.org/2001/XMLSchema-instance"으로 나타나는 결과가 나타났습니다.

서비스 호출 생성 마법사를 사용하면 패키지가 생성되는데,이 경우에는 "services.acrs_surveys"라고합니다.

private static var serializer0:JSONSerializationFilter = new JSONSerializationFilter(); 
private static var serializer1:XMLSerializationFilter = new XMLSerializationFilter(); 

직렬화가 사용될이 클래스 세트의 생성자 : operation.serializationFilter인지

operation = new mx.rpc.http.Operation(null, "GetSurvey"); 
operation.url = "Get/{itemid}"; 
operation.method = "GET"; 
argsArray = new Array("itemid"); 
operation.argumentNames = argsArray;   
operation.serializationFilter = serializer0; 
operation.properties = new Object(); 
operation.properties["urlParamNames"] = ["itemid"]; 
operation.resultType = valueObjects.Survey; 
operations.push(operation); 

주 패키지에 "_Super_Acrs_surveys()"헤더에서 두 직렬 선언 클래스이며 이 작업의 데이터가 실제로 XML인데도 serializer0으로 설정합니다. JSON 직렬 변환기입니다. 마법사가 데이터 형식을 올바르게 감지하지 못했기 때문에 문제가있는 것 같습니다.

serializer를 serializer1로 변경했는데 이제는 내 코드가 작동합니다.

흥미롭게도 XML에서 문자열을 반환하는 작업이 올바르게 감지되었습니다. 따라서 제 질문에서 언급 한 것처럼 작동했습니다.