5 Replies Latest reply on May 1, 2008 6:35 PM by ntsiii

    The format of XML file returned from web service

    May 2008
      Hi everyone,

      My web service (build in asp.net 2.0 with C#) returns the following xml file which is not what I want.

      <Root>
      <Root2>
      <Person> .... </Person>
      <Person> .... </Person>
      <Person> .... </Person>
      ......
      </Root2>
      </Root>

      But I want my web service to return the following xml file. How can I get the following xml file instead of the above xml file ? Thanks.

      <Root>
      <Person> .... </Person>
      <Person> .... </Person>
      <Person> .... </Person>
      ......
      </Root>
        • 1. Re: The format of XML file returned from web service
          Gregory Lafrance Level 6
          Isn't the webservice just returning the data as is? Maybe you need to process the result returned in a different way.
          • 2. Re: The format of XML file returned from web service
            ntsiii Level 3
            Yes, the format of the xml is determined by the web service itself, not Flex.

            Well, that is not quite true. Have you set resultFormat="e4x" on your flex WebService instance? result Format will not change one xml format to another, but it will convert the xml to an object tree if you leave resultFormat at the default.

            Now, if you do not have control over the server / web service, you can manipulate the xml on the client.

            Tracy
            • 3. The format of XML file returned from web service
              MayLam18 Level 1
              Thanks for everyone's reply!

              Sorry, I don't know where to set resultFormat="e4x". Below is my code. And LINE 111 gives error. And the error message is below. And the xml returned from the web service is below.

              Error: Error #2093: The Proxy class does not implement getDescendants. It must be overridden by a subclass.
              at Error$/throwError()
              at flash.utils::Proxy/ http://www.adobe.com/2006/actionscript/flash/proxy::getDescendants()
              at LogIn/loginHandler()[P:\JIMMY-FLEX\Flex_LogIn\LogIn.mxml:58]
              at flash.events::EventDispatcher/dispatchEventFunction()
              at flash.events::EventDispatcher/dispatchEvent()
              at mx.rpc::AbstractService/dispatchEvent()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\A bstractService.as:232]
              at mx.rpc::AbstractOperation/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\3.0.x\frameworks\pro jects\rpc\src\mx\rpc\AbstractOperation.as:193
              at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\3.0.x\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:191
              at mx.rpc::Responder/result()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:4 1]
              at mx.rpc::AsyncRequest/acknowledge()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:74]
              at DirectHTTPMessageResponder/completeHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\ messaging\channels\DirectHTTPChannel.as:381]
              at flash.events::EventDispatcher/dispatchEventFunction()
              at flash.events::EventDispatcher/dispatchEvent()
              at flash.net::URLLoader/onComplete()


              <?xml version="1.0" encoding="utf-8"?>
              <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%" xmlns:ns1="*">


              <mx:Script>
              <![CDATA[

              import mx.rpc.events.ResultEvent;
              namespace FaciNS = " http://FaciNet.com/";

              import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;
              import mx.rpc.soap.WebService;

              //public var __xmlResult:XML;
              public var ws:WebService;


              public function Log_In(UN:String, PW:String):void
              {
              ws.Login(UN, PW);

              }

              public function getLoginData():void {

              loadWSDL();
              Log_In(UN.text, PW.text);
              }

              public function loadWSDL():void
              {

              ws = new mx.rpc.soap.WebService();
              ws.wsdl = " http://localhost:50779/VS2008_LogIn/Service.asmx?wsdl"
              ws.useProxy = false;
              ws.addEventListener("fault", faultHandler);
              ws.addEventListener("result", loginHandler);
              ws.loadWSDL();
              }


              public function loginHandler(e:ResultEvent):void {
              var wkSouID:String = e.result[0]..SouID; // LINE 111

              trace(wkSouID);
              }

              public function faultHandler(event:FaultEvent):void
              {
              dispatchEvent(new Event("Error"));
              }

              public function checkUser(UName:String, PWord:String):void {
              getLoginData();
              }

              ]]>
              </mx:Script>

              <mx:Panel id="loginPanel" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="400" height="200" x="97" y="66">
              <mx:Form id="loginForm" width="100%" height="100%">
              <mx:FormItem label="Username:" color="red">
              <mx:TextInput id="UN" />
              </mx:FormItem>
              <mx:FormItem label="Password:" color="red">
              <mx:TextInput id="PW"/>
              </mx:FormItem>
              </mx:Form>
              <mx:ControlBar>
              <mx:Spacer width="100%" id="spacer1"/>
              <mx:Button label="Login" id="loginButton" click="checkUser(UN.text, PW.text)" />
              </mx:ControlBar>
              </mx:Panel>

              </mx:Canvas>



              <?xml version="1.0" encoding="utf-8" ?>
              - <ArrayOfLogIn xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns=" http://tempuri.org/">
              - <LogIn>
              <SouID>2</SouID>
              <LogInUserID>3</LogInUserID>
              <LogInUserName>samlam</LogInUserName>
              <Password>abc123</Password>
              <DialectID>4</DialectID>
              <CreatedByUserID>5</CreatedByUserID>
              <UpdatedByUserID>5</UpdatedByUserID>
              </LogIn>
              - <LogIn>
              <SouID>3</SouID>
              <LogInUserID>4</LogInUserID>
              <LogInUserName>samlam</LogInUserName>
              <Password>abc123</Password>
              <DialectID>4</DialectID>
              <CreatedByUserID>5</CreatedByUserID>
              <UpdatedByUserID>5</UpdatedByUserID>
              </LogIn>
              </ArrayOfLogIn>
              • 4. The format of XML file returned from web service
                MayLam18 Level 1
                I have just solved my problem.

                Replace LINE 111 by the following line:

                var wkSouID:String = e.result[0].valueOf().SouID.toString();

                And it works.

                Thanks,
                May
                • 5. Re: The format of XML file returned from web service
                  ntsiii Level 3
                  The reason for that error is you were trying to use the e4x "descendants" operator, but do not have xml. Flex has converted your data to a nested object structure. YOU DO NOT WANT THIS.

                  You can set restulFormat on the WebSevice instance, or on individual operations:
                  ws.resultFormat = "e4x";

                  Then, in you handler, do:
                  trace(XML(e.result).toXMLString()); //to see what you have

                  Then go back to your previous e4x expression.

                  Tracy