18 Replies Latest reply: Aug 11, 2009 10:02 AM by DanNZN RSS

    Flex communicate with Web Service is slow

    TigerLittle
      My web service code is :
      <mx:WebService id="MyServices" destination="myWS" useProxy="true" showBusyCursor="true" makeObjectsBindable="false">
      <mx:operation name="getCred">
      <mx:request xmlns="">
      <Username>
      {username.text}
      </Username>
      <Password>
      {password.text}
      </Password>
      </mx:request>
      </mx:operation>
      <mx:operation name="getPlants">
      <mx:request xmlns="">
      <Cred>
      {credModel}
      </Cred>
      </mx:request>
      </mx:operation>
      </mx:WebService>

      It uses proxy. When I call it, it click button and call getCred(event) in ActionScript:
      public function getCred(event:Event):void{
      MyServices.getCred.send();
      }

      And result:
      <mx:Model id="credModel">
      {MyServices.getCred.lastResult}
      </mx:Model>

      My problem is the time from I click button to call the send() to the browse display my cred value takes about 6-7 seconds. And same time to call other web service operation. It is an unacceptable long time. Any one knows why it takes so long time and how to solve it?

      Thanks.
        • 1. Re: Flex communicate with Web Service is slow
          ntsiii Community Member
          What control are you using to display the data?

          If you are using the proxy, turn on webservice debugging in the flex-config.xml file, run the flex server from a command window, and observer the data flow.

          You may see that it is not the data call that is taking the time, but rather the UI rendering.

          On the other hand, the web service might just be slow.

          Tracy
          • 2. Re: Flex communicate with Web Service is slow
            TigerLittle Community Member
            Thank you, Tracy.

            I didn’t display the CredModel, just use it as a request parameter for next web service operation. After I got getPlants response, I display data by DataGrid.

            I can’t find webservice debugging in my flex-config.xml, the only line about debug is:
            <!-- generate swfs and swds for debugging -->
            <!-- query parameter override - ?debug=true/?debug=false -->
            <debug>true</debug>

            Tracy, could you please teach me how to set webservice debugging and how to run flex server from command window? Thanks again.

            Actually, we are doing presale evaluation. We did same web service call by JSF, it is much faster. So, I really want to know why it take so long time in Flex.
            • 3. Re: Flex communicate with Web Service is slow
              ntsiii Community Member
              What is your application server? You can't do what I suggested using Tomcat because it always runs as a service.

              It might be easier to time the response in Flex .

              Create a variable at the application level, say iSendCall:Number;
              Then, in the code where you do the send(), do:
              iSendCall = getTimer();

              Then in the result handler function, do:
              var iReturn:Number = getTimer();
              alert("Elapsed: " + (iReturn - iSendCall);

              This will tell you the number of milliseconds it took for the data to return.

              Tracy
              • 4. Re: Flex communicate with Web Service is slow
                TigerLittle Community Member
                Many thanks, Tracy. And sorry for my poor English.

                I did same way to show the time as you said. But, my boss wants to know more detail where is the time spent, I think time spend on data call, web service response, UI rendering.....

                And I am using tomcat as the localhost server. From the tomcat window, I can see when I click button “get Cred”, it send request to web service immediately, but it takes long time to see response come back. And at once, the browse shows data. But we did test by using JSF to call same web service. It is fast. So, I don’t think web service is slow. And the UI rendering is ok too. Maybe the time spend on Flex communicate with web service(Java). I think there should someone also have some problem as me. I hope someone know the solution to speed up.

                I found how to run flex debug in command window, and I can run fdb, but when I click "where is the Debug or Profile running" , my browse is dead. Many things I need to learn.

                • 5. Re: Flex communicate with Web Service is slow
                  ntsiii Community Member
                  Did you use getTimer exactly as I suggested, in the send() and result handler function?

                  What was the elapsed time?

                  Tracy
                  • 6. Re: Flex communicate with Web Service is slow
                    TigerLittle Community Member
                    I used differenct function. in the send()
                    myDate1 = new Date();
                    timeLab1.text=myDate1.time.toString();
                    in the result handler function:
                    myDate2 = new Date();
                    timeLab2.text=myDate2.time.toString();
                    timeDiff=myDate2.time-myDate1.time;

                    and show timeDiff in a inputArea, it shows 7227ms. and it show Busy Cursor when borwse waiting for the reponse.
                    • 7. Re: Flex communicate with Web Service is slow
                      ntsiii Community Member
                      Ok, that is fine, and you are measuring the actual data call time. And that IS slow!

                      Is that a public web service? One that I can test against?

                      I am concerned, because I do not know of any way to affect what happens between the send() and the result.

                      Can you test against some other web service to see if it is slow as well?

                      Tracy
                      • 8. Re: Flex communicate with Web Service is slow
                        TigerLittle Community Member
                        Hi Tracy

                        This is not public web service, it is my company web service. And we did JSP, ASP to call same ws, it is fast.

                        I did test with a very small web service, it run little bit faster than this.

                        Here is my code, I did many test by it. so, it is not neat, sorry. Could you take a look on it? you may found out the problem. Thank you very much.

                        <?xml version="1.0"?>
                        <!-- Simple example to demonstrate the HDividedBox layout -->
                        <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*">
                        <mx:Script>
                        <![CDATA[
                        import mx.utils.ObjectUtil;
                        import mx.rpc.events.ResultEvent;
                        import mx.utils.StringUtil;
                        import mx.utils.ArrayUtil;
                        import mx.collections.*;
                        import mx.rpc.soap.*;
                        import mx.logging.*;

                        [Bindable]
                        public var selectedNode:Object;

                        [Bindable]
                        public var XLC:XML;

                        [Bindable]
                        public var result:Array;

                        [Bindable]
                        public var selectedCred:Object;

                        [Bindable]
                        public var selectedRoot:Object;
                        [Bindable]
                        public var WebPuid:String;

                        [Bindable]
                        public var webRootInfo:Object;
                        [Bindable]
                        public var folderXML:Object;

                        [Bindable]
                        public var xmlData:XMLListCollection;

                        [Bindable]
                        public var arData:Array;
                        [Bindable]
                        public var fcID:String;
                        [Bindable]
                        public var acData:ArrayCollection;
                        [Bindable]
                        public var myDate1:Date;
                        [Bindable]
                        public var myDate2:Date;
                        [Bindable]
                        public var timee:Number;

                        // Event handler for the Tree control change event.
                        public function treeChanged(event:Event) : void
                        {
                        selectedNode=Tree(event.target).selectedItem;
                        }

                        public function getCred(event:Event):void{
                        MyServices.getCred.send();

                        var logger:ILogger = Log.getLogger("mx.messaging.Channel");
                        logger.debug("nxx:Start time: {0}", myDate1.time.toString());

                        selectedCred = MyServices.getCred.lastResult;
                        logger.debug("nxx:End time: {0}, total:{1}", myDate2.time.toString(), timee);

                        }

                        public function getRoot(event:Event):void{
                        myDate1 = new Date();
                        timeLab1.text=myDate1.time.toString();

                        MyServices.getWebRoot.send();
                        //MyServices.getFolderContents.send();

                        }

                        public function getFolder(event:Event):void{
                        MyServices.getFolderContents.send();

                        }
                        public function handleWebRoot(event:ResultEvent):void{
                        webRootInfo=event.result;
                        myDate2 = new Date();
                        timeLab2.text=myDate2.time.toString();
                        timee=myDate2.time-myDate1.time;

                        myrootid.text=webRootInfo.ContentFolder.Puid;
                        }

                        public function handleFolderContents(event:ResultEvent):void{
                        folderXML=event.result;
                        }

                        ]]>
                        </mx:Script>


                        <mx:Model id="credModel">
                        {MyServices.getCred.lastResult}
                        </mx:Model>

                        <!--mx:Model id="webRootInfo">
                        {MyServices.getWebRoot.lastResult.ContentFolder}
                        </mx:Model-->

                        <!--mx:Model id="treeModel">
                        {MyServices.getFolderContents.lastResult}
                        </mx:Model-->

                        <mx:WebService id="MyServices" destination="cetgWS" useProxy="true" showBusyCursor="true" makeObjectsBindable="false">
                        <mx:operation name="getCred">
                        <mx:request xmlns="">
                        <Username>
                        {username.text}
                        </Username>
                        <Password>
                        {password.text}
                        </Password>
                        </mx:request>
                        </mx:operation>
                        <mx:operation name="getWebRoot" result="handleWebRoot(event)">
                        <mx:request xmlns="">
                        <Credentials>
                        {credModel}
                        </Credentials>
                        <WebRootItemId>
                        Ddb1000160-GEN-001
                        </WebRootItemId>
                        </mx:request>
                        </mx:operation>
                        <mx:operation name="getFolderContents" result="handleFolderContents(event)" resultFormat="e4x">
                        <mx:request xmlns="">
                        <Credentials>
                        {credModel}
                        </Credentials>
                        <FolderPuid>
                        {webRootInfo.ContentFolder.Puid}
                        </FolderPuid>
                        </mx:request>
                        </mx:operation>
                        </mx:WebService>



                        <mx:HDividedBox width="90%" height="90%">

                        <mx:VDividedBox width="30%" height="100%">

                        <mx:Panel title="Accordion Container Example" height="65%" width="100%"
                        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
                        <mx:Label text="Select an Accordion navigator button to change the panel."/>
                        <mx:Accordion id="accordion" width="100%" height="100%">
                        <mx:VBox label="Panel 1" height="100%" width="100%">
                        <mx:Label text="CETG Services"/>
                        <mx:Label text="User Name:"/>
                        <mx:TextInput id="username"/>
                        <mx:Label text="Password:"/>
                        <mx:TextInput id="password" displayAsPassword="true"/>
                        <mx:Button label="Get Credentail" click="getCred(event)"/>
                        <mx:Button label="Get WebRoot" click="getRoot(event)"/>
                        <mx:Button label="Get folder Content" click="getFolder(event)"/>
                        </mx:VBox>

                        </mx:Accordion>
                        </mx:Panel>

                        <mx:Panel title="Tree Control Example" height="35%" width="100%"
                        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
                        <mx:Tree id="myTree" width="100%" height="100%" labelField="@label"
                        showRoot="false" dataProvider="{folderXML}" change="treeChanged(event)"/>
                        </mx:Panel>
                        </mx:VDividedBox>

                        <mx:Panel title="TabNavigator Container Example" height="100%" width="70%"
                        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
                        <mx:TabNavigator id="tn" width="100%" height="100%">
                        <!-- Define each panel using a VBox container. -->

                        <mx:VBox label="Panel 1">
                        <mx:Label text="Time:"/>
                        <mx:TextInput id="timeinp" text="{timee}"/>
                        <mx:Label text="credential:"/>
                        <mx:TextInput id="credinp" text="{credModel.Puid}"/>
                        <mx:Label id="selectedCol" />
                        <mx:Label id="timeLab1" />
                        <mx:Label id="timeLab2" />

                        </mx:VBox>

                        <mx:VBox label="Panel 2">
                        <mx:TextInput id="myrootid" />
                        <mx:DataGrid id="wrData" dataProvider="{webRootInfo.ContentFolder}" width="80%">
                        <mx:columns>

                        <mx:DataGridColumn dataField="StyleFolder" headerText="GID"/>
                        <mx:DataGridColumn dataField="ContentFolder" headerText="Name"/>
                        <mx:DataGridColumn dataField="Puid" headerText="Puid"/>
                        <mx:DataGridColumn dataField="Name" headerText="Name"/>
                        </mx:columns>
                        </mx:DataGrid>
                        </mx:VBox>

                        </mx:TabNavigator>
                        </mx:Panel>
                        </mx:HDividedBox>
                        </mx:Application>
                        • 9. Re: Flex communicate with Web Service is slow
                          ntsiii Community Member
                          I am sorry, I do not know what else to suggest. I do not see anything wrong with your code, and besides, I don't know of anything you can do in code that affects the time of a webservice data return.

                          I'll keep thinking.

                          Tracy
                          • 10. Re: Flex communicate with Web Service is slow
                            ntsiii Community Member
                            Perhaps you could try calling the webservice without the proxy?
                            • 11. Re: Flex communicate with Web Service is slow
                              ntsiii Community Member
                              Try running this sample app. It reports the elapsed time in a label to the right of the TextArea. I get about 445ms.
                              Tracy

                              • 12. Re: Flex communicate with Web Service is slow
                                TigerLittle Community Member
                                You are right, i should try without proxy. But the problem is I did without proby before, it doesn't work.
                                Now, I am trying it on Flex 1.5.
                                • 13. Re: Flex communicate with Web Service is slow
                                  ntsiii Community Member
                                  If you do not use the proxy, and the web service is not on the EXACT same domain as the Flex app, then you must have a crossdomain.xml file in the root of the web site serving the web service.

                                  Tracy
                                  • 14. Re: Flex communicate with Web Service is slow
                                    TigerLittle Community Member
                                    Tracy:
                                    I try to use without proxy. and set crossdomain.xml file at the root of the server. but when i still can't access webserivce. it give me error:
                                    [RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL ( http://MyServer:8080/services/MyServices?wsdl)"

                                    Any idea about this error? Thank you.



                                    • 15. Re: Flex communicate with Web Service is slow
                                      TigerLittle Community Member
                                      oh, sorry, here is my corssdomain.xml file:
                                      <cross-domain-policy>
                                      <allow-access-from domain="company.com"/>
                                      </cross-domain-policy>
                                      • 16. Re: Flex communicate with Web Service is slow
                                        ntsiii Community Member
                                        Try the full permission domain spec:
                                        domain="*"

                                        And the file needs to go in the root of the WEB applcation. If in doubt put it everywhere until it works, them remove til it breaks.

                                        Tracy
                                        • 17. Re: Flex communicate with Web Service is slow
                                          TigerLittle Community Member
                                          Tracy,
                                          I did like this:
                                          deployed 2 web services on my tomcat. One called Mytest, one is Myservice. The Mytest is I wrote for test, this is my simple. Myservice is the really web service we will use. I copied the Myservice.war file and deployed on my tomcat. Then my code like:

                                          <mx:WebService id="mytest" wsdl=" http://localhost:8080/MyTest/Mytest.wsdl" showBusyCursor="true">
                                          <mx:operation name="xxxx” />
                                          </mx:WebService>
                                          <mx:WebService id="myservice" wsdl=" http://localhost:8080/MyService/Myservice.wsdl" showBusyCursor="true">
                                          <mx:operation name="xxxx” />
                                          </mx:WebService>

                                          We I run, I got error:

                                          RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL ( http://localhost:8080/ MyService/Myservice.wsdl)"]
                                          Mytest.wsdl has no problem to run. But if I use proxy,

                                          <mx:WebService id="myServices" destination="myWS" useProxy="true" showBusyCursor="true" makeObjectsBindable="false">

                                          Myservice also can run. Do you have any idea about this error?
                                          Today I did try code by new released version 2, but same slow. So, I still want to try call Myservice web service without proxy.

                                          Thank you.
                                          • 18. Re: Flex communicate with Web Service is slow
                                            DanNZN

                                            I am wondering if this ever got resolved because I am experiencing the same problems. The web service call is taking forever 5-6 seconds to respond. If i call to the same web service from .Net it is very fast.

                                             

                                            The web services and swf files are on the same server which is using https and basic authentication. I am not using a proxy.

                                             

                                            Any help would be greatly appreciated.