6 Replies Latest reply on Apr 22, 2009 11:00 AM by _Natasha_

    how to invoke a web service

    carlodonz

      Hi all, i'm new in this forum... my problem is: i've to invoke a web service by a flex client.

      Specifically, the method i've to invoke requires in input 2 files xml. After having done this, i've to call another method to get a string formatted in xml...

       

      Here there is my code.. but it doesn't work....Someone can help me please??

       

      Thank you!

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:All="*" layout="absolute" creationComplete="startup();">

       

           <mx:Script>
                <![CDATA[
                     import mx.rpc.events.ResultEvent;

       

                     private var processURL:URLRequest = new URLRequest("../assets/process.xml");
                     private var simulationURL:URLRequest = new URLRequest("../assets/simulation.xml");
                     private var processLoad:URLLoader;
                     private var simulationLoad:URLLoader;
                     [Bindable]
                     private var stringProcess:String;
                     [Bindable]
                     private var stringSimulation:String;

       

                     private function startup():void {
                          processLoad = new URLLoader(processURL);
                          simulationLoad= new URLLoader(simulationURL);
                          processLoad.addEventListener(Event.COMPLETE,processHandler);
                          simulationLoad.addEventListener(Event.COMPLETE,simulationHandler);
                     }

       

                     private function remotingCFCHandler(e:ResultEvent):void {
                          tbox.text=e.result.toString();
                     }

       

                     public function processHandler(ev:Event):void {
                          stringProcess=XML(processLoad.data).toXMLString();
                     }
                     public function simulationHandler(ev:Event):void {
                          stringSimulation=XML(simulationLoad.data).toXMLString()
                     }
                    
                     public function onClick(): void{
                          ws.createAndStartSimulationFromXML(stringProcess,stringSimulation);
                          ws.createAndStartSimulationFromXML.send();
                          ws.getSimulatedTime();
                     }
                ]]>
           </mx:Script>

       

           <mx:WebService id="ws" useProxy="false" wsdl="http://localhost:8080/TestSim10.02.09/services/SimulatorWSInterface?wsdl" >
                <mx:operation name="createAndStartSimulationFromXML">
                     <mx:request>
                          <XMLProcessDescription>{stringProcess}</XMLProcessDescription>
                          <XMLSimulationDescription>{stringSimulation}</XMLSimulationDescription>
                     </mx:request>
                </mx:operation>
           </mx:WebService>

       

          
           <mx:Button x="10" y="10" label="Button" click="onClick()"/>
           <mx:Text x="10" y="40"  text="{ws.getSimulatedTime.lastResult}" id="tbox"/>
      </mx:Application>

        • 1. Re: how to invoke a web service
          _Natasha_ Level 4

          You don't send load request

           

                         private function startup():void {

                              processLoad = new URLLoader(); // it's only constructor!
                              simulationLoad= new URLLoader();
                              processLoad.addEventListener(Event.COMPLETE,processHandler);
                              simulationLoad.addEventListener(Event.COMPLETE,simulationHandler);

                              processLoad.load(processURL); // start loading!
                              simulationLoad.load(simulationURL);
                         }

          • 2. Re: how to invoke a web service
            carlodonz Level 1

            i've made yours changes but i get this error...

             

            [RPC Fault faultString="SOAP Response cannot be decoded. Raw response: "

            faultCode="DecodingError" faultDetail="null"]

                at mx.rpc.soap::Operation/

            http://www.adobe.com/2006/flex/mx/internal::processSOAP()[C

            :\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\soap\Operation.as:874]

                at mx.rpc.soap::Operation/

            http://www.adobe.com/2006/flex/mx/internal::processFault()[C

            :\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\soap\Operation.as:805]

                at mx.rpc::AbstractInvoker/

            http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C

            :\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:218]

                at

            mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder. as:53]

                at

            mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRe quest.as:103]

                at

            DirectHTTPMessageResponder/errorHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\m x\messaging\channels\DirectHTTPChannel.as:362]

                at flash.events::EventDispatcher/dispatchEventFunction()

                at flash.events::EventDispatcher/dispatchEvent()

                at flash.net::URLLoader/onComplete()

             

             

            what is this?

             

            2009/4/22 Natasha <forums@adobe.com>

             

            You don't send load request

            >

                           private function startup():void {

                                processLoad = new URLLoader(); // it's only

            constructor!

                                simulationLoad= new URLLoader();

            >

            processLoad.addEventListener(Event.COMPLETE,processHandler);

            >

            simulationLoad.addEventListener(Event.COMPLETE,simulationHandler);

                                processLoad.load(processURL); // start loading!

                                simulationLoad.load(simulationURL);

                           }

            >

            • 3. Re: how to invoke a web service
              _Natasha_ Level 4

              Do you get this error before you click button or after?

               

              If before - check that url to your files are correct. (In debug mode you can view the full url to file for URLLoader)

              If after - it cann't decode the answer from your webservice.

              • 4. Re: how to invoke a web service
                carlodonz Level 1

                i get that error after i click the button... maybe i have to specify in

                <mx:operation name="getSimulatedTime"/> the object return type??

                 

                2009/4/22 Natasha <forums@adobe.com>

                 

                Do you get this error before you click button or after?

                >

                If before - check that url to your files are correct. (In debug mode you

                can view the full url to file for URLLoader)

                If after - it cann't decode the answer from your webservice.

                >

                • 5. Re: how to invoke a web service
                  carlodonz Level 1

                  i've specified this:

                   

                  </id>

                              </mx:request>

                          </mx:operation>

                   

                  now in the text area where i should get the SOAP response i get this string

                  message:

                   

                  what is that???

                   

                  2009/4/22 Carlo Donzelli <carlodonz@gmail.com>

                   

                  i get that error after i click the button... maybe i have to specify in

                  <mx:operation name="getSimulatedTime"/> the object return type??

                  >

                  2009/4/22 Natasha <forums@adobe.com>

                  >

                  Do you get this error before you click button or after?

                  >>

                  >> If before - check that url to your files are correct. (In debug mode you

                  >> can view the full url to file for URLLoader)

                  >> If after - it cann't decode the answer from your webservice.

                  >>

                  • 6. Re: how to invoke a web service
                    _Natasha_ Level 4

                    Try to set resultFormat attribute for operation. possible values are "object|xml|e4x". If it's xml - you can use "xml" or "e4x", "object" for other variants.