Select to view content in your preferred language

How to parse the result in Flex after calling a SOE?

1338
5
12-26-2012 03:21 PM
XintaoLiu
Deactivated User
I created a rest SOE using VS2010 C#, and then deployed it on server machine. How to call the Rest SOE in Flex Client? Any example or suggestion? Thanks in advance!
Tags (2)
0 Kudos
5 Replies
XintaoLiu
Deactivated User
I created a rest SOE using VS2010 C#, and then deployed it on server machine. How to call the Rest SOE in Flex Client? Any example or suggestion? Thanks in advance!


Or may I ask that how to call Rest SOEs in Flex and parse the result Json to get valid values?
0 Kudos
IvanBespalov
Frequent Contributor
how to call

ESRI sample "SOE GetElevations" demonstrates how to create own Task based on BaseTask.
All the Flex API samples are also included in the Flex API Library download.

how to parse

It depends on your server object extension response. What is your SOE response format? JSON, xml, amf ?..
For example: this service SOE response format is JSON - must be pasrsed as JSON.
0 Kudos
DasaPaddock
Esri Regular Contributor
You can also use the JSONTask if you don't want to create your own task:
http://resources.arcgis.com/en/help/flex-api/apiref/com/esri/ags/tasks/JSONTask.html
0 Kudos
MarkDeaton
Esri Contributor
Xinato,

Here's a FlexViewer widget I wrote; it calls an elevation data SOE through REST and then handles the resulting JSON.
http://www.arcgis.com/home/item.html?id=b9d247c297f144459854751740f59f68

The SOE URL is here:
http://sampleserver6.arcgisonline.com/arcgis/rest/services/Elevation/WorldElevations/MapServer/exts/ElevationsSOE_NET/ElevationLayers/0/GetElevations


I use a Flex HTTPService object to make the call. I do it this way because I wrote the code a while ago. You might also use a BaseTask to do the same thing.
Here's the MXML declaration:
<s:HTTPService showBusyCursor="true" method="POST" id="websvcElevations" url="{_configXML.elevationSOEURL}" resultFormat="text"/>


And here's a bit of the code that makes the call and handles the response:
var sGeoms:String = JSONUtil.encode( [ event.graphic.geometry ] );
var oParams:Object = {
 "f"    : "json",
 "geometries" : sGeoms
}
     
// Send geometries off to SOE to get elevations
var atToken:AsyncToken = websvcElevations.send( oParams );
atToken.addResponder( new AsyncResponder( 
 
 //--- Handle results from elevation profile SOE ---//
 function( event:ResultEvent, token:Object ):void {
  try {
   var oResult:Object = JSONUtil.decode( event.result.toString() );
   if ( oResult.hasOwnProperty( "error" ) )
    showError( "The server returned an error:\n" + oResult.error.message );
   else { ... }


I hope that helps.
0 Kudos
XintaoLiu
Deactivated User
Thank you all for your replies! I have solved it, but just come back to look the posts.
0 Kudos