4 Replies Latest reply on May 10, 2010 11:02 AM by ssardar

    Web Service Result Handling

    ssardar Level 1

      I'm new to flex and was looking for the best way to display my web service result in AdvancedDataGrid.

      Could someone please take the time to spellout how to do this.

       

      I have tried it using the MXML approach and the AS code...I keep thinking I am missing something.

       

      Basically I am returning an Array of a custom defined Object,.  Everything in the object is a string, so it's not overly complex.

       

      I'm certain my service is returning a response as I have checked it with soapUI.

       

      So how do I map this result over to a ArrayCollection??

       

       

       

      <mx:WebService id="srv" wsdl="wsDest"

      <mx:operation name="getGridData"

      fault="showErrorDialog(event)"

      result="somefunction(event)"

      >

       

      </mx:operation>

       

       

      </mx:WebService>

       

       

      <mx:Script>

      <![CDATA[

       

      import mx.rpc.soap.SOAPFault;

       

      import mx.rpc.events.ResultEvent;

       

      import mx.rpc.events.FaultEvent;

       

      import mx.controls.Alert;

       

      import mx.collections.ArrayCollection;

       

       

      [

      Bindable]

       

      public var myArray : ArrayCollection = new ArrayCollection();

       

       

      public function log(event:ResultEvent):void {

       

      // Handle result.

      myArray = ArrayCollection(event.result);

       

      trace(event.result);

       

      }

       

       

       

      ]]>

       

      </mx:Script>

       

       

       

      My current error:

      Error #1088: The markup in the document following the root element must be well-formed.

       

      So am I forgetting something?  Do I need to strip out the SOAP Headers?  Any Ideas?

       

       

      I've tried the above approch amongst others...but would like someone to spell out a definitive approach to this.  Any help is greatly appreciated, thanks in advance.

        • 1. Re: Web Service Result Handling
          Marcello Rego

          Hello. Down i put a example of websevice usage. First you have to use a valid wsdl parameter, and the result is by default in a XML format. This code will show this.

           

          <mx:WebService id="service"
               wsdl="http://wslite.strikeiron.com/phonenumberinfolite01/PhoneNumberInfoLite.asmx?WSDL">

           

          <mx:operation
               name="GetLocationInfoForPhoneNumber"
               result="result(event)"
               fault="fault(event)"/>


          </mx:WebService>

           

           

          <mx:Script>
          <![CDATA[
          import mx.utils.ObjectUtil;
          import mx.controls.Alert;
          import mx.rpc.events.FaultEvent;
          import mx.rpc.events.ResultEvent;
          private function search():void
          {
          service.GetLocationInfoForPhoneNumber(areaCode.text, threeDigits.text);
          }
          private function result(e:ResultEvent):void
          {
          Alert.show(ObjectUtil.toString(e.result));
          }
          private function fault(e:FaultEvent ) : void
          {
          Alert.show(e.fault.message);
          }
          ]]>
          </mx:Script>

          1 person found this helpful
          • 2. Re: Web Service Result Handling
            Radhakrishna Bhat Level 3

            Can you re-check your WSDL file/SOAP response? there must not be any unclosed tags.

             

            -Radhakrishna

            • 3. Re: Web Service Result Handling
              Marcello Rego Level 1

              Sorry.

              I put below a new example of Webservice usage.

               

              The first question and problem is that the ArrayCollection creation parameter was wrong. You must especify it like that

               

              new ArrayCollection(e.result.toArray());

               

               

              Example:

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
                 
                  <mx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                      import mx.collections.ListCollectionView;
                      import mx.utils.ObjectUtil;
                      import mx.controls.Alert;
                      import mx.rpc.events.FaultEvent;
                      import mx.rpc.events.ResultEvent;

               

                      [Bindable]
                      private var categories:ListCollectionView = new ArrayCollection();
                     
                      private function search():void
                      {
                          service.getCategories();
                      }
                     
                      private function result(e:ResultEvent):void
                      {
                          categories = e.result as ListCollectionView;
                      }
                     
                      private function fault(e:FaultEvent ) : void
                      {
                          Alert.show(e.fault.message);
                      }
                  ]]>
                  </mx:Script>
                 
                  <mx:WebService id="service"
                      wsdl="http://feeds.adobe.com/webservices/mxna2.cfc?WSDL">
                      <mx:operation
                           name="getCategories"
                           result="result(event)"
                           fault="fault(event)"/>
                  </mx:WebService>

               

                  <mx:Button label="GET CATEGORIES" click="search()"/>
                 
                  <mx:DataGrid dataProvider="{categories}">
                     
                      <mx:columns>
                         
                          <mx:DataGridColumn dataField="categoryId" headerText="ID" />
                          <mx:DataGridColumn dataField="categoryName" headerText="NAME" />
                         
                      </mx:columns>
                     
                  </mx:DataGrid>

               

              </mx:Application>

              • 4. Re: Web Service Result Handling
                ssardar Level 1

                Marcello,

                 

                  Thank you, these two items were key.  It works correctly now.  Thanks again.

                 

                 

                 

                       new ArrayCollection(e.result.toArray());

                 

                 

                      private function result(e:ResultEvent):void
                        {
                            categories = e.result as ListCollectionView;
                        }