5 Replies Latest reply on Mar 6, 2008 8:30 PM by MyNickSG

    Problem invoking .net's webservice with flex 3

    MyNickSG Level 1
      I am trying to call “validateListData” function in which i am calling “checkMarketSegment”. Based on the result returned by the result handler of checkMarketSegment(i.e checkMarketSegmentResultsHandler), some action has to be taken. But the result handler is being called only after the complete processing of “validateListData” function, i.e i am not getting the value returned by that function on the same line at which i am calling checkMarketSegment function. What could be the possible solution for this?


      here is the code:

      private function validateListData():Boolean
      {
      var IsValidMarketList:Boolean=true;
      var marketSegmentId:String;
      if (rbCreateNew.selected== true)
      {
      if (tiMarketName.text == "")
      {
      Alert.show("Please enter new list name.");
      IsValidMarketList=false;
      return;
      }
      if (checkMarketSegment(this.tiMarketName.text))
      {
      Alert.show("List name already exists.");
      IsValidMarketList=false;
      return;
      }
      }
      }

      private function checkMarketSegment (marketsegment:String): Boolean
      {
      var importFunctions:ImportFunctions=new ImportFunctions();
      var arraryGlobal:ArrayOfGlobalSessionVariables=GlobalFunctions.arr;
      if(arraryGlobal.length>0)
      {
      var globalVariables:GlobalSessionVariables=arraryGlobal[1];
      globalCompanyId=globalVariables.companyId;
      importFunctions.checkMarketSegment(globalCompanyId,marketsegment,this);
      }
      return importFunctions.isExistingMarketList;
      }

      public function checkMarketSegment(companyId:String,marketSegment:String,impList:ImportList):void
      {
      importList=impList;
      var wsNML:LeadManagement= new LeadManagement();
      wsNML.addLeadManagementFaultEventListener(faultHandler);
      wsNML.addcheckMarketSegmentEventListener(checkMarketSegmentResultsHandler);
      wsNML.checkMarketSegment(companyId,marketSegment);
      }

      private function checkMarketSegmentResultsHandler(e:CheckMarketSegmentResultEvent):void
      {
      isExistingMarketList=Boolean(e.result);
      }

      Please suggest some possible solution for this. Text
        • 1. Re: Problem invoking .net's webservice with flex 3
          kcell Level 2
          Hi MyNickSG,

          you have to redesign your app.

          A webservice call is a async operation and the flex framework didn´t capsulate this async operation. (.Net webservice classes provide sync call, but the call itself is still async).

          So you have to throw a event (validateListDataEvent) when the webservice call returned. The validateListData function just invoke the webservice call.
          The class which calls validateListData can register to your custom validateListDataEvent and in the eventHandler function you can display the outcome however you like it.

          Hope this will help you.

          kcell
          • 2. Re: Problem invoking .net's webservice with flex 3
            MyNickSG Level 1
            thanks for the reply..

            that means i need to call my webservice first, and then i use my logic to proceed further?

            As i need the result at that step only? i mean within the function flow. As for example i need to call the function to get the value back based on the parameter passed. i.e at each step I am calling my function to get some value(returned by webservice), that value needs to be displayed as an alert. so please suggest some possible solution for dis kind of situation also.
            • 3. Re: Problem invoking .net's webservice with flex 3
              kcell Level 2
              Hi,

              yes, you first have to wait until the webservice returned and than proceed with you logic.

              The reason is that the app just use one thread, which can not be blocked, cause otherwise the webservice never will return. (flash didn´t support multiple threading)

              I know that this can be very frustating ( I was in a similar situation) and I didn´t found any other solution for this behaviour, so I made my app driven by events.

              If anybody has found another solution I would be glad to here it.

              kcell
              • 4. Re: Problem invoking .net's webservice with flex 3
                ntsiii Level 3
                Nope, you got it, all data access is asynchronous, and there is no code blocking.

                Events are the only way to go.

                in your validateListData function go ahead and call the webservice. (via the checkMarketSegment func is fine) But do not try to do anything else in either of those functions.

                Declare a resultEvent listener on the WebService or operation, and point it at a function like onResult(). In that function, test your event.result value and continue your logic. (show the Alert, or whtever.)

                This IS a PITA if you are used to synchronous operations, but there is no alternative.

                Tracy
                • 5. Re: Problem invoking .net's webservice with flex 3
                  MyNickSG Level 1
                  thanks all..i changed my logic..and its wrking now..