Flex to ASP.NET - best way to attach a FeatureSet to the request for an ASP page

04-17-2012 01:31 PM
New Contributor II
If I have a QueryTask in Flex that is generating a FeatureSet, what is the best way to pass the features in the FeatureSet to an ASP.NET page? QueryString? Should I use JSON to incode the results? If necessary I can just pass an Array with two strings and two real numbers per record, I do not need the graphics object.
Tags (2)
0 Kudos
1 Reply
New Contributor II
After some effort I came up with the below. BTW: Thanks Rex Hanson for realizing that some of us might need to do this outside of ESRI: http://rexdotnet.blogspot.com/2009/11/using-arcgis-server-rest-api-in-net.html Next Dev Summit I owe you a beer!


queryTask.execute(query, new AsyncResponder(onResult, onFault));
    function onResult(featureSet:FeatureSet, token:Object = null):void
     jsonResults = featureSet.toJSON();
                                                                               var request:URLRequest = new URLRequest("http://bwiespape/GeotechExample2ASP/simple.aspx");
                    request.data = { j: jsonResults};
                                                                               // if you don't need a file back you could just as easily use HTTPService here
                    var fileRef:FileReference = new FileReference();


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim serializer As JavaScriptSerializer

        Dim nvc As NameValueCollection = Request.Form
        Dim responseString As String = nvc("j")

        serializer = New JavaScriptSerializer()

        If responseString IsNot Nothing Then

            Dim results As IDictionary(Of String, Object) = TryCast(serializer.DeserializeObject(responseString), IDictionary(Of String, Object))

            If results IsNot Nothing AndAlso results.ContainsKey("features") Then
                Dim features As IEnumerable(Of Object) = TryCast(results("features"), IEnumerable(Of Object))

                For Each feature As IDictionary(Of String, Object) In features
                    Dim attributes As IDictionary(Of String, Object) = TryCast(feature("attributes"), IDictionary(Of String, Object))

                    Dim project_nu As String = TryCast(attributes("Project_Nu"), String)
                    Dim pointid As String = TryCast(attributes("PointID"), String)
                    Dim east As Double = Decimal.ToDouble(CDec(attributes("East")))
                    Dim north As Double = Decimal.ToDouble(CDec(attributes("North")))

                    'Do Something with your results, array, whatever
            End If
        End If
    End Sub
0 Kudos