2 Replies Latest reply on Mar 17, 2008 11:53 AM by ntsiii

    XML and Web Services

      Hi !

      I have a problem using web services... I have the next action script class:

      package cwdi.clientws
      import mx.rpc.soap.WebService;
      import mx.rpc.soap.LoadEvent;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.Fault;
      import mx.controls.Alert;

      public class ClientWS

      //private var CONSTANTES : CONSTANTS = new CONSTANTS();
      private var webService : WebService = new WebService();
      private var action: String = new String();
      private var xmlQuery:String = new String();
      public var xmlResponse:String;

      //public var xmlQuery:String = new String(query.generateXMLQueryCategorias("holas",15));
      public function loadWebService (url_wsdl:String, action:String, xmlQuery:String) : void
      // Cargar el WSDL y agregar listeners para saber cuando este listo

      this.action = action;
      this.xmlQuery = xmlQuery;

      webService.wsdl = url_wsdl;

      webService.addEventListener(LoadEvent.LOAD, onWSDL);

      webService.addEventListener(FaultEvent.FAULT, onWebServiceFault);


      //listener que avisa cuando el WSDL se ha cargado

      private function onWSDL ( event : LoadEvent ) : void
      // Llamada a un metodo en el WebService, primero se crea otro listener para saber cuando
      // el resultado esta listo.
      webService.executeActionOnCategorias.addEventListener(ResultEvent.RESULT, getResult);

      public function getResult ( event : ResultEvent ) : void
      // Usar el resultado. Para mas detalles se puede inspecionar event.result en el debugger.
      //textArea.text += "La temperature maxima para hoy en " + event.result.PlaceName + " , "+ event.result.StateCode + " es : " + event.result.Details[0].MaxTemperatureC + "C";
      //var x= new XML(event.result.toString());

      mx.controls.Alert.show(this.xmlResponse+" getResult");


      // En caso de que el WebService no puede ser cargado.

      private function onWebServiceFault(event:FaultEvent ):void
      var fault: Fault = event.fault;
      var message:String = "An error occurred. The details are as follows\ncode: " + fault.faultCode;

      message += "\ndetail: " + fault.faultDetail;
      trace("Web Service Error :" + message);
      public function getXmlResponse():String
      return this.xmlResponse;

      public function setXmlResponse(xmlRespon:String):void



      but when y recover the xmlResponse var at the MXML and the xmlResponse is equal NULL... Why? Could you help me please! I thought that ActionSript is similar to JAVA and the xmlResponse var must contains the response String...

      Help me please!
        • 1. Re: XML and Web Services
          SujitG Level 2
          If the object instance invoking the web service and the object instance on which you are reading the xmlResponse are same, then the xmlResponse string should contain the value. Can you make sure if you are trying to access the xmlResponse variable after the web service response is received. i.e access the xmlResponse object after the getResult() method is invoked by the Web Service component.
          Hope this helps.
          • 2. Re: XML and Web Services
            ntsiii Level 3
            1) unless you have a good reason to choose otherwise, you should set the resultFormat property of the WebService operation/method equal to "e4x" If you do not, then Flex converts your XML into a nested dynamic object structure. There is alnost no benefit to this.

            instead, set resultFormat="e4x". then in the result handler function, do:
            public function getResult ( event : ResultEvent ) : void
            var xmlResult:XML = event.result as XML;

            Do this first to make sure you aer getting your data.

            Also, it is probably a mistake to name a string variable xmlResponse. The xml prefix implies that variable contains XML