Select to view content in your preferred language

populate a datagrid from a HTTPservice

1418
16
08-30-2010 11:18 AM
RichardKrell
New Contributor
I am using code provided from the Code Gallery http://resources.esri.com/arcgisserver/apis/flex/index.cfm?fa=codeGalleryDetails&scriptID=15872 to try and populate a datagrid with data obtained in a HTTPservice. The webservice was written by me and works fine. I have used it in other applications. the code I am using on the HTTPserice is as follows:

<mx:HTTPService id="hsID"
url="http://data.cmap.illinois.gov/ws/tip/tipservice.asmx/getproject"
showBusyCursor="true"
requestTimeout="120"
useProxy="false"/>

I know I need to take the results and create a ArrayCollection but I am having problems figuring out the correct code so it will iterate through the selected points and return the data to the datagrid.
Any assistance would be greatly appriciated.

Thanks
Richard Krell
Chicago Metropolitan Agency for Planning
Tags (2)
0 Kudos
16 Replies
RichardKrell
New Contributor
Robert,
To be honest I am getting confused and that is probably my biggest problem.  I took some code as I mentioned in the beginning that was using the querytask and now I am trying to re-write it to use HTTPservice.

I have always had problems with this and I don't know why.  I have done apps in VB, Avenue, and many others for years but this Flex for some reason has me tearing my hair out.

So yes I am trying to use HTTPservice to retrieve these records.  I know the webservice is OK because I have been using it.  You can try it if you want and just enter a ID 01-06-0068.  I will return one record.
0 Kudos
ReneRubalcava
Frequent Contributor II
Ok, sorry. I got confused reading your earlier posts. Looking at what you have, you actually want to use a WebService, not an HTTPService. You'd use a WebService to send requests to a function and get results. An HTTPService would be used to load something like an XML or Text file.

Here is an example of using a WebService with your service. Don't worry about converting to XML unless that's your thing.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      minWidth="955"
      minHeight="600"
      applicationComplete="init()">

 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 </fx:Declarations>
 <fx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.soap.mxml.WebService;
   
   protected var service:WebService;
   
   protected function init():void {
    service = new WebService();
    service.showBusyCursor = true;
    service.wsdl = "http://data.cmap.illinois.gov/ws/tip/tipservice.asmx?wsdl";
    service.addEventListener(ResultEvent.RESULT, onResultsLoaded_handler);
    service.addEventListener(FaultEvent.FAULT, onFault_handler);
    service.loadWSDL();
   }
   
   protected function onFault_handler(event:FaultEvent):void {
    Alert.show("Error in calling service: " + event.message, "Error");
   }
   
   protected function onResultsLoaded_handler(event:ResultEvent):void {
    try {
     dgResults.dataProvider = event.result as ArrayCollection;
    }
    catch (e:Error) {
     Alert.show("An error occurred loading results: " + e.message, "Results error");
    }
   }
   
   
   protected function btnRequest_clickHandler(event:MouseEvent):void {
    
    service.getproject(input.text);
   }
  ]]>
 </fx:Script>
 <s:layout>
  <s:VerticalLayout gap="5"
        horizontalAlign="center"
        paddingTop="25" />
 </s:layout>
 <s:TextInput id="input"
     width="200" />
 <s:Button id="btnRequest"
     label="Send Request"
     width="200"
     click="btnRequest_clickHandler(event)" />
 <mx:DataGrid id="dgResults"
     width="800"
     height="300" />
</s:Application>



Now as far as how this relates to the example you linked in your first post, the above will get you the ArrayCollection of results you were looking for in your first post. Now you can use those results to create a "where" query on your map service.
0 Kudos
RichardKrell
New Contributor
Thanks for the latest response and believe me I will look at it. I spent last evening working on this and I came up with something different. 

I am also attaching the file and the actionscript class file. Again, unfortunetly these are examples I found as I was researching this. I know it is probably that I have been working on this for so long that it has become so hard but I really do appriciate everyone's help.
0 Kudos
RichardKrell
New Contributor
Is this code written in Flash 4 or Flex 3.6 because although we are due for upgrading we are still working in 3.6?

Ok, sorry. I got confused reading your earlier posts. Looking at what you have, you actually want to use a WebService, not an HTTPService. You'd use a WebService to send requests to a function and get results. An HTTPService would be used to load something like an XML or Text file.

Here is an example of using a WebService with your service. Don't worry about converting to XML unless that's your thing.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955"
               minHeight="600"
               applicationComplete="init()">
 
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.soap.mxml.WebService;
 
            protected var service:WebService;
 
            protected function init():void {
                service = new WebService();
                service.showBusyCursor = true;
                service.wsdl = "http://data.cmap.illinois.gov/ws/tip/tipservice.asmx?wsdl";
                service.addEventListener(ResultEvent.RESULT, onResultsLoaded_handler);
                service.addEventListener(FaultEvent.FAULT, onFault_handler);
                service.loadWSDL();
            }
 
            protected function onFault_handler(event:FaultEvent):void {
                Alert.show("Error in calling service: " + event.message, "Error");
            }
 
            protected function onResultsLoaded_handler(event:ResultEvent):void {
                try {
                    dgResults.dataProvider = event.result as ArrayCollection;
                }
                catch (e:Error) {
                    Alert.show("An error occurred loading results: " + e.message, "Results error");
                }
            }
 
 
            protected function btnRequest_clickHandler(event:MouseEvent):void {
 
                service.getproject(input.text);
            }
        ]]>
    </fx:Script>
    <s:layout>
        <s:VerticalLayout gap="5"
                          horizontalAlign="center"
                          paddingTop="25" />
    </s:layout>
    <s:TextInput id="input"
                 width="200" />
    <s:Button id="btnRequest"
              label="Send Request"
              width="200"
              click="btnRequest_clickHandler(event)" />
    <mx:DataGrid id="dgResults"
                 width="800"
                 height="300" />
</s:Application>
 


Now as far as how this relates to the example you linked in your first post, the above will get you the ArrayCollection of results you were looking for in your first post. Now you can use those results to create a "where" query on your map service.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Richard,

  Here is Rene's code downgraded for Flex Builder 3

The real question is are you part of the domains that has access to this web service look at the http://data.cmap.illinois.gov/crossdomain.xml
is your machine part of one of these?

<allow-http-request-headers-from domain="*.pathfinder-development.com" headers="*"/>
<allow-http-request-headers-from domain="*.greatarc.com" headers="*"/>
<allow-http-request-headers-from domain="208.70.17.37" headers="*"/>
<allow-http-request-headers-from domain="localhost" headers="*"/>


If so then Rene's code should work.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
 layout="vertical" creationComplete="init()">
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.soap.mxml.WebService;
   
   protected var service:WebService;
   
   protected function init():void {
    service = new WebService();
    service.showBusyCursor = true;
    service.wsdl = "http://data.cmap.illinois.gov/ws/tip/tipservice.asmx?wsdl";
    service.addEventListener(ResultEvent.RESULT, onResultsLoaded_handler);
    service.addEventListener(FaultEvent.FAULT, onFault_handler);
    service.loadWSDL();
   }
   
   protected function onFault_handler(event:FaultEvent):void {
    Alert.show("Error in calling service: " + event.message, "Error");
   }
   
   protected function onResultsLoaded_handler(event:ResultEvent):void {
    try {
     dgResults.dataProvider = event.result as ArrayCollection;
    }
    catch (e:Error) {
     Alert.show("An error occurred loading results: " + e.message, "Results error");
    }
   }
   
   
   protected function btnRequest_clickHandler(event:MouseEvent):void {
    
    service.getproject(input.text);
   }
  ]]>
 </mx:Script>

 <mx:TextInput id="input"
     width="200" />
 <mx:Button id="btnRequest"
     label="Send Request"
     width="200"
     click="btnRequest_clickHandler(event)" />
 <mx:DataGrid id="dgResults"
     width="800"
     height="300" />
</mx:Application>
0 Kudos
RichardKrell
New Contributor
Thaks Robert,
I was just in the process of re-writing the code into 3.  Yes, I am part of the crossdomain.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Richard,

  Good, as I am not in that list I can not test to see if it works but everything in the code looks good so give it a test.
0 Kudos