3 Replies Latest reply on Jan 10, 2007 7:01 PM by Newsgroup_User

    Displaying webservice results

    Dan_Orth
      I am new to both flex and web services and am trying to create a simple application to just return the results of a web service (from xignite.com). I am able to get my data grid to display the results fine when I use an external XML file or use a model within the application mirroring what I believe I am getting back from the web service. The problem seems to be when I try to then use the actual service as the data provider and not the module. I would also like it in the future to be able to display the results (such as Name, Symbol, Last, etc.) in text fields or labels. I am hopping I am on the right track here and that I am not missing an easier way to do this. My code is below and any comments would be greatly appreciated! Thank you!
      -Dan


      <?xml version="1.0"?>
      <!-- Simple example to demonstrate the WebService tag. -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.soap.LoadEvent;
      import mx.rpc.soap.*;

      public function onMyResult(event: ResultEvent) :void
      {
      var myObject:Object = Object(event.result);
      }

      /* private function myLabelFunc(item:Object, column:DataGridColumn):String
      {
      if (item.Quote.Symbol==undefined)
      {return null;}
      else
      {return item.Quote.Symbol + " " + item.Quote.Last;}
      } */

      private function returnLast(item:Object, column:DataGridColumn):String
      {
      {return item.ExtendedQuote.Quote.Last;}
      }

      private function returnSymbol(item:Object, column:DataGridColumn):String
      {
      {return item.ExtendedQuote.Quote.Symbol;}
      }

      private function returnName(item:Object, column:DataGridColumn):String
      {
      {return item.ExtendedQuote.Name;}
      }

      private function returnOutcome(item:Object, column:DataGridColumn):String
      {
      {return item.ExtendedQuote.Outcome;}
      }

      ]]>
      </mx:Script>

      <mx:WebService id="WS" wsdl=" http://www.xignite.com/xQuotes.asmx?WSDL" useProxy="false" showBusyCursor="true" makeObjectsBindable="false" fault="Alert.show(event.fault.toString(),'Error')">
      <mx:operation name="GetQuote" resultFormat="xml">
      <mx:request>
      <Symbol>{stockSymbol.text}</Symbol>
      </mx:request>
      </mx:operation>
      </mx:WebService>

      <mx:Model id="stockQuoteModel">
      <root>
      <ExtendedQuote>
      <Outcome>Success</Outcome>
      <Identity>Cookie</Identity>
      <Delay>0.5625</Delay>
      <Name>MICROSOFT CP</Name>
      <Exchange>NASDAQ</Exchange>
      <Quote>
      <Symbol>MSFT</Symbol>
      <Previous_Close>29.98</Previous_Close>
      <Open>29.82</Open>
      <High>29.86</High>
      <Low>29.62</Low>
      <Last>29.64</Last>
      <Bid>29.55</Bid>
      <Bid_Size>N/A</Bid_Size>
      <Ask>29.67</Ask>
      <Ask_Size>N/A</Ask_Size>
      <Percent_Change>-1.13</Percent_Change>
      <Change>-0.34</Change>
      <Volume>37974456</Volume>
      <High_52_Weeks>30.26</High_52_Weeks>
      <Low_52_Weeks>21.46</Low_52_Weeks>
      <Date>12/22/2006</Date>
      <Time>4:00:00 PM</Time>
      </Quote>
      </ExtendedQuote>
      </root>
      </mx:Model>

      <mx:Panel title="WebService Example" height="75%" width="75%" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
      <mx:Label width="100%" color="blue" text="Enter a stock symbol to obtain a quote."/>
      <mx:TextInput id="stockSymbol" text="NSM"/>
      <mx:Button label="Get Quote" click="WS.GetQuote.send()"/>
      <mx:Label text="{WS.GetQuote.result}" fontWeight="bold" id="stockquote"/>
      <!--<mx:DataGrid id="dataGridStock" dataProvider="{mx.utils.ArrayUtil.toArray(stockQuoteModel)}"> -->
      <mx:DataGrid id="dataGridStock" dataProvider="{WS.getQuote.result()}">
      <mx:columns>
      <mx:DataGridColumn headerText="Symbol" labelFunction="returnSymbol"/>
      <mx:DataGridColumn headerText="Last" labelFunction="returnLast"/>
      <mx:DataGridColumn headerText="Name" labelFunction="returnName"/>
      <mx:DataGridColumn headerText="Outcome" labelFunction="returnOutcome"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:Text text="{WS.getQuote.ExtendedQuote.result.Outcome}"/>
      <mx:Text text="{WS.getQuote.result.Outcome}"/>
      <mx:Text text="{WS.getQuote.result.ExtendedQuote.Outcome}"/>
      <mx:Text text="{WS.getQuote.Outcome}"/>
      <mx:TextInput text="{WS.getQuote.Quote.Last}"/>
      <mx:TextInput text="{WS.getQuote.Last.result}"/>
      <mx:TextInput text="{WS.getQuote.ExtendedQuote.Quote.Last}"/>
      <mx:TextArea width="641" height="114" id="myTextArea" text="{WS.getQuote.result.ExtendedQuote.Quote.Last}"/>

      </mx:Panel>

      </mx:Application>
        • 1. Re: Displaying webservice results
          Level 1
          What is the actual problem you are experiencing? (i.e. the details of what is not working correctly). Are you getting an error message? What does it say?

          Thanks,
          Andy
          • 2. Re: Displaying webservice results
            synapse7
            Wow, sorry about that Andy - I see I completely forgot to mention the actual problem there - not sure what happened. When I try to use the Xignite web service and call it with the .getSend() Get Quote button nothing happens - I don't see any results displayed in the data grid or any of the text fields. As you can see I am trying a lot of things to try to get the syntax right but so far nothing. Do I need to include result="" in the operation as well? So far I cannot seem to make it give me an error message or get something useful in the debugger which is really slowing things down.
            -Dan
            • 3. Re: Displaying webservice results
              Level 7
              Ok, I figured it out - I think it just took me leaving it alone for a while
              when I got sick for a few weeks but here is what worked for me. Hoping it
              can help someone else starting up!



              <?xml version="1.0"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

              <mx:Script>
              <![CDATA[
              import mx.controls.Alert;
              import mx.rpc.events.ResultEvent;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.soap.LoadEvent;
              import mx.rpc.soap.*;

              public function onMyResult(event: ResultEvent) :void
              {
              var myObject:Object = Object(event.result);
              }

              private function myLabelFunc(item:Object, column:DataGridColumn):String
              {
              if (item.Quote.Symbol==undefined)
              {return null;}
              else
              {return item.Quote.Symbol + " " + item.Quote.Last;}
              }

              private function returnLast(item:Object,
              column:DataGridColumn):String
              {
              {return item.Quote.Last;}
              }

              private function returnSymbol(item:Object,
              column:DataGridColumn):String
              {
              {return item.Quote.Symbol;}
              }

              ]]>
              </mx:Script>

              <mx:WebService id="WS" wsdl=" http://www.xignite.com/xQuotes.asmx?WSDL"
              useProxy="false"
              showBusyCursor="true"
              fault="Alert.show(event.fault.toString(),'Error')">

              <mx:operation name="GetQuote" resultFormat="object">
              <mx:request>
              <Symbol>{stockSymbol.text}</Symbol>
              </mx:request>
              </mx:operation>
              </mx:WebService>

              <mx:Panel title="WebService Example" height="75%" width="75%"
              paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
              <mx:Label width="100%" color="blue" text="Enter a stock symbol to
              obtain a quote."/>
              <mx:TextInput id="stockSymbol" text=""/>
              <mx:Button label="Get Quote" click="WS.GetQuote.send()"/>
              <mx:Label text="Company: {WS.GetQuote.lastResult.Name}"
              fontWeight="bold"/>
              <mx:Label text="Symbol: {WS.GetQuote.lastResult.Quote.Symbol}"/>
              <mx:Label text="Last Price: ${WS.GetQuote.lastResult.Quote.Last}"/>
              <mx:DataGrid id="dgStock" dataProvider="{WS.GetQuote.lastResult}">
              <mx:columns>
              <mx:DataGridColumn headerText="Symbol"
              labelFunction="returnSymbol"/>
              <mx:DataGridColumn headerText="Name" dataField="Name"/>
              <mx:DataGridColumn headerText="Last Price" labelFunction="returnLast"/>
              </mx:columns>
              </mx:DataGrid>
              </mx:Panel>

              </mx:Application>