2 Replies Latest reply on May 20, 2011 9:34 AM by BigZ2011

    HTTPService getting hit from emulator but not from phone itself

    BigZ2011

      I'm developing an app that hits two HTTPServices - one after the other. My app works great in the emulator but the deployed app only hits the first HTTPService and doesn't seem to hit the 2nd one at all. I'm completely stumped and if anyone could help me, I'd be eternally grateful. My code is below. Many thanks in advance!

       

      <fx:Declarations>

      <!-- Place non-visual elements (e.g., services, value objects) here -->

                 

      <s:HTTPService id="WebServiceNumber1" resultFormat="text"

         result="ProcessOutputsOfWebServiceNumber1(event)" showBusyCursor="true">

         <s:url>http://domain.com/api/json?blah&sensor=false</s:url>

      </s:HTTPService>

       

                 

      <s:HTTPService id=”WebServiceNumber2" resultFormat="text" result="ProcessOutputsOfWebServiceNumber2(event)" showBusyCursor="true">

      <s:url>http://domain.com/api/asdf/json?blah&sensor=false</s:url>

      </s:HTTPService>

       

      </fx:Declarations>

       

                 

      private function init():void

      {

      // I want to hit the 2nd web service after the 1st one has completed

      WebServiceNumber1.addEventListener("result",CallWebServiceNumber2);

      WebServiceNumber1.send();     // No problems

      }

       

      private function ProcessOutputsOfWebServiceNumber1(event:ResultEvent):void

      {

      var strJSONResponse:String = String(event.result);

      // stuff gets done, everything works

      }                             

       

      private function CallWebServiceNumber2(event:ResultEvent):void

      {

                      WebServiceNumber2.send();//works in emulator, not sure about phone

                      lblTest.text = " WebServiceNumber2.send() has been fired off...";

                      // the above statement does work and the label gets changed

      }

       

       

      private function ProcessOutputsOfWebServiceNumber2(event:ResultEvent):void

      {

                      var strJSONResponse:String = String(event.result); //works in emulator, not phone

                      lblTest.text = strJSONResponse;               //works in emulator, not phone

      }

       

       

        • 1. Re: HTTPService getting hit from emulator but not from phone itself
          blazejewicz Level 4

          Hi,

           

          #1

          consider adding handlers for FaultEvent to see if there is something wrong at runtime

           

          #2

          you could fire your second http service from already defined handler for first service (not sure why you've declared two different handlers to just do the same work - but in different places). So your "ProcessOutputsOfWebServiceNumber1" handler could be used to do both features (handling results and updating second service) I think

           

          #3

          you could try to update params string by adding random id to check if what you're observing could be due to caching on device, see very easy implementation:

          [Bindable]

          private var randomID:int = 0;

          protected function udpateServiceHandler(event:MouseEvent):void

          {

               randomID = (new Date().getTime());

               WebServiceNumber2.send();

          }

          <s:HTTPService id="WebServiceNumber2" resultFormat="text" showBusyCursor="true">

               <s:url>http://www.domain.com/index.php?rid={randomID}</s:url>

          </s:HTTPService>

          Before you call send() on webservice just update random param and that change will be propagated via bindings,

           

          regards,

          Peter

          • 2. Re: HTTPService getting hit from emulator but not from phone itself
            BigZ2011 Level 1

            Peter - Thank you very much for your help.  As it turns out, the problems was with a bad parameter - great call. Not sure why it wasn't an issue for the emulator but I'm glad that problem has been solved. As to your question about my multiple event handlers - they do very different jobs on the different data returned by the two services. You couldn't have known that from my simplified code sample.  Thanks a million!!