9 Replies Latest reply on Jul 19, 2010 5:36 AM by CapgeminiAndy

    Multiple HTTP requests using single HTTPService component

    BhaskerChari Level 4

      Hi,

       

      I am having one requirement, I need to use a single HTTPService component to send request to a same and single ASP.net multiple times.

       

      How can I acheive that..? I know that I can acheive this by sending one request at a time and after the "result" event is called for the first request then sending the second request and so on...

       

      But if I do so then it will be delayed response as I need to wait until the result handler for the previous request is called...

       

      So how do I do this..?

       

      Any help greatly appreciated....:)

       

       

      Thanks in advance..

       

      Thanks,

      Bhasker Chari

        • 1. Re: Multiple HTTP requests using single HTTPService component
          UbuntuPenguin Level 4

          Why would waiting for the response handler be too long ?  Not to mention , Flex can only have 2 connections to the same ip address I assume any attempted connections over the browser-enforced-limits will just get queued up.  If you have BlazeDS you could set up a polling-service and use the Consumer/Producers in Flex/AS3 , that sounds more like what you are trying to do.

          • 2. Re: Multiple HTTP requests using single HTTPService component
            dave cragg Level 2

            It's possible to send mutliple requests simultaneously with a single HTTPService instance. There is a "concurrency" property which is set to "multiple" by default.

             

            If you do this, you need to work out a way to manage the result events so you can distinguish which result corresponds to which call. There are probably many ways to do this, depending on your needs. One way is to set properties on the AsyncToken that is returned from the HTTPService.send() method. The AsyncToken is a dynamic object so you can set your own additional properties on it. For example, you could set a "callback" property that points to a Function to call when the service call returns. You can retrieve the AsyncToken from the ResultEvent.

            1 person found this helpful
            • 3. Re: Multiple HTTP requests using single HTTPService component
              mxvx Level 1

              Hi,

               

              As ubuntu said, even if you have multiple Http or remote services, the browser will open only 2 connections at a time.  If you are calling a service 5 times, the calls get queued.  Flex will wait for the result of all the services.

               

              I assume that your problem is to avoid the delayed response. Even I had the same problem and we used multiple channels to resolve the issue. I hope the follwoing link migh help you.

               

              http://cookbooks.adobe.com/post_Performance_tip__Use_multiple_duplicated_remote_ob-10663.h tml

               

              Thanks & Regards

              mxvx

              • 4. Re: Multiple HTTP requests using single HTTPService component
                dave cragg Level 2

                I wasn't aware of the 2 connections limit, but does that only apply to HTTPService when setting a destination?

                 

                Here I have useProxy set to false and set the url of the HTTPService directly. On a Mac with Safari as the browser, I send 5 HTTPService requests in sequence to the same url. Monitoring the traffic with tcpdump, all five request are sent before any response is received.

                • 5. Re: Multiple HTTP requests using single HTTPService component
                  timjowersboa Level 1

                  I'm researching this too. Dave, please post what you find. My understanding is IE was deficient (old design requirements) on this. IE6 limited to 2. IE7 more. (5?). and IE8 configurable but defaults to 6.

                   

                  I am not sure about HTTPService. Does it run through the browser or open its own sockets? If it is truly limited to 2 is this for IE6 but more for FF, IE8?

                   

                  Also, for an embedded Flash app, does the HTTPService then interfere with the AJAX calls?

                   

                  We planned to use Flex (Flash) instead of an applet but perhaps we've made a grave error here.

                   

                   

                  Does anyone know how this works?

                   

                  TIA,

                  Tim Jowers

                  • 6. Re: Multiple HTTP requests using single HTTPService component
                    timjowersboa Level 1

                    Its ugly. IE8 limits to 6.

                    Using multiple HTTPService instances does not help.

                    HTTPService does work through teh browser and is controlled by the browser setting.

                     

                    We hate to fall on our sword but looks like an applet might be back on the table. This one hurts bad. With friends like this...

                     

                     

                    Ok, so now off to test the setting for IE8.

                    http://www.tech-recipes.com/rx/4140/ie8-increase-the-maximum-connections-limit-to-download -more-than-six-files-at-one-time/

                    As it the MaxConnectionsPerServer instructions from another page did not work and must have been for IE6 or so.

                    • 7. Re: Multiple HTTP requests using single HTTPService component
                      timjowersboa Level 1

                      yep, the setting works when set to 10. Seemed to not work when set to 20. Anyways, summary is "long polling" and Flex

                      or Flash are not good compatriates. So, you will need to work out your own mechanism on the server or client

                      side to limit the sockets used/wasted. Painful but true.

                       

                       

                      <?xml version="1.0" encoding="utf-8"?>

                      <mx:Application

                       

                       

                      xmlns:mx="http://www.adobe.com/2006/mxml">

                      <mx:Script>

                      <![CDATA[

                       

                       

                      import com.util.HTTPServiceProxy;

                       

                      import mx.rpc.events.FaultEvent;

                       

                      import mx.rpc.events.ResultEvent;

                       

                      import mx.rpc.http.HTTPService;

                       

                       

                      private var urlOpenTasksDefault:String = HTTPServiceProxy.servercontext + "/blahblah?something=somethign";

                       

                      private var waitRequestPart:String = "&wait=5000&lastUpdate=" // long polling period for now for testing

                       

                       

                      private var iResponses:int;

                       

                       

                      private function runTest(urlString:String):void{

                       

                      var service:HTTPService = new HTTPService();

                      service.url= urlString;

                      service.resultFormat =

                      "e4x";

                      service.method =

                      "get";

                      service.contentType=

                      "application/xml";

                      service.addEventListener(

                      "result", httpResult);

                      service.addEventListener(

                      "fault", httpFault);

                      service.send();

                      }

                       

                       

                      public function httpResult(event:ResultEvent):void {

                       

                      trace("httpResult " + iResponses++ );

                      }

                       

                      public function httpFault(event:FaultEvent):void {

                       

                      trace("httpFault " + (iResponses++) + event.fault.faultString);

                      }

                       

                       

                      private function test1(evt:Event):void {

                      iResponses=0;

                       

                      var reqs:int = parseInt(requests.text);

                       

                      for( var i:int=0; i<reqs; i++ ){

                      runTest(urlOpenTasksDefault);

                      }

                      }

                       

                      private function test2(evt:Event):void {

                      iResponses=0;

                       

                      var reqs:int = parseInt(requests.text);

                       

                      for( var i:int=0; i<reqs; i++ ){

                      runTest(urlOpenTasksDefault+waitRequestPart+

                      "0");

                      }

                      }

                      ]]>

                      </mx:Script>

                       

                       

                      <mx:Label text="Requests"/>

                       

                      <mx:TextInput id="requests"/>

                       

                      <mx:Button label="Test Requests-Responses" click="test1(event)"/>

                       

                      <mx:Button label="Test Long Polling" click="test2(event)"/>

                      </mx:Application>

                      • 8. Re: Multiple HTTP requests using single HTTPService component
                        timjowersboa Level 1

                        Does AMF (RemoteObject, BlazeDS) also suffer this restriction?

                        • 9. Re: Multiple HTTP requests using single HTTPService component
                          CapgeminiAndy

                          yes also AMF is suffering this resitriction, even AIR