Select to view content in your preferred language

populate a datagrid from a HTTPservice

1422
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
DasaPaddock
Esri Regular Contributor
You may want to try using Flash Builder's Data -> Connect to HTTP... menu option. This wizard will generate code that you can use to call your service.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Richard,

   If you what to know how to do it without using adobes autogenerated code than all you have to do is this

private function getproject_result(evt:ResultEvent):void {
       var pRslt:Object = evt.result;
}

<mx:WebService id="webService" wsdl="http://data.cmap.illinois.gov/ws/tip/tipservice.asmx?wsdl" showBusyCursor="true">
        <mx:operation name="getproject"
                resultFormat="object"
                fault="getproject_fault(event);"
                result="getproject_result(event);">
                <mx:request><projectid>{sProjectId}</projectid></mx:request>
        </mx:operation>
    </mx:WebService>
0 Kudos
RichardKrell
New Contributor
I appriciate everyone's response and I guess I haven't explained myself. The progblem is not the service call. As I said that is working fine. Where I am having problems is creating an ArrayCollection that will populate my grid with all the records that have been selected.

thanks
Richard Krell
Chicago Metropolitian Agency for Planning.
0 Kudos
RichardKrell
New Contributor
A little more info.

Here is what I am working with right now trying to get it working.

function onXMLResult(event:ResultEvent, featureSet:FeatureSet, token:Object = null😞void{
for(var i:uint = 0; i < featureSet.features.length; i++){
xml = event.result.ArrayOfTipproject.tipproject;
}
dgrid1.dataProvider = xml;

}

Needless to say, it is not working but I have just written it and am working through the errors.


0 Kudos
ReneRubalcava
Frequent Contributor II
Try this
You can go XML -> Array or ArrayCollection
Don't forget to set your result format.
service.resultFormat = "e4x";
var xml:XML = event.result as XML;
var items:Array = [];
for each (var queryXML:XML in xml.tipProject) {
 var obj:Object = {
 project:queryXML.@project,
 agency:queryXML.@agency // and so on adding the fields you want
 }
 items.push(obj);
}


You can also turn it into an XMLListCollection
var xmlListCollection:XMLListCollection = new XMLListCollection();
xmlListCollection.source = new XMLList( event.result );

You can then treat the XMLListCollection like an ArrayCollection

When dealing with an HTTPService, your results are easy to parse in XML, I never used ArrayCollection with an HTTPService result, but I think the event.result object is xml by default.
0 Kudos
RichardKrell
New Contributor
I started this thread the other day in an attempt to resolve a coding problem I am having and received some really good answers. But after being deverted for a day on another project I am back and hate to keep being such a bother but I am truely over my perverbial head. Below is the funtion I am trying to get working but I keep getting an error 1034 telling me I cannot covert a featureset into an resultevent. I believe I understand the error but don't understand where it is coming from.



//*************************************************************************
public function runQueryTask(geometry:Geometry):void {

 
//*************************************************************************
[INDENT]

var queryTask:QueryTask = new QueryTask();


 

queryTask.url = "http://data.cmap.illinois.gov/ArcGIS/rest/services/Maps/TIP_Test/MapServer/0";

 
 
 
[LEFT]var query:Query = new Query();

query.geometry = geometry;
[LEFT]query.returnGeometry = true;
query.spatialRelationship = "esriSpatialRelContains";
query.outFields = ['PROID','PROGRAMMIN','COMPLETION'];[/LEFT]
[/LEFT]

 
 
 
 

queryTask.execute(query, new AsyncResponder(onXMLResult, onFault));

 
 
 

function onXMLResult(event:ResultEvent, token:Object=null):void{

 
 
[INDENT]

//xml = event.result.ArrayOfTipproject.tipproject;


 
[LEFT]var xmlListCollection:XMLListCollection = new XMLListCollection;

xmlListCollection.source = new XMLList(event.result.ArrayOfTipproject.tipproject);
[LEFT]var items:Array = [];
foreach(var queryXML:XML in xmlListCollection){[/LEFT]
[/LEFT]

 
 
 
[INDENT]

var obj:Object = {


 

project:queryXML.@PROID,

agency:queryXML.@PROGRAMMIN


 
 
 
 
[/INDENT]}
 
[/INDENT]}

items.push(obj);

 
[/INDENT]}
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Richard,

   Just change your onXMLResult to

function onXMLResult(featureSet:FeatureSet, token:Object = null):void
0 Kudos
RichardKrell
New Contributor
I am trying to retrieve the information from a SQL database via a HTTPservice not through the featureset.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Richard,

   You definently have me confused then as your code snippet above had
var queryTask:QueryTask = new QueryTask();

 
queryTask.url = "http://data.cmap.illinois.gov/ArcGIS/rest/services/Maps/TIP_Test/MapServer/0";


So are you talking about querying a map service layer using the query task or a web service like you began this thread with???
0 Kudos