private string RequestPayload(GeometryServiceRequest geometryServiceRequest) { var requestPayload = ""; var properties = geometryServiceRequest.GetType().GetProperties(); foreach (var reportField in properties) { object value = reportField.GetValue(geometryServiceRequest); Type type = reportField.GetType(); Console.WriteLine(reportField.Name); Console.WriteLine(value); double[] dd = value as double[]; string[] ss = value as string[]; if (dd != null) { requestPayload += reportField.Name + "=" + dd[0] + "," + dd[1] + "&"; } else if (ss != null) { requestPayload += reportField.Name + "="; foreach (string s in ss) { requestPayload += s + ","; } requestPayload = requestPayload.Remove(requestPayload.Length - 1, 1); //remove final ',' requestPayload += "&"; } else requestPayload += reportField.Name + "=" + value + "&"; } return requestPayload.Remove(requestPayload.Length - 1, 1); //remove final '&' }
private void GeometryWithinUSStateRequest(double x, double y) { //US State layer used to return the name of the State that the point X, Y is within. //It uses the layer itself to perform the geometric operation rather than a Geometry service. //If you wanted to use a geometry service you could look here: //http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer string requestURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?"; GeometryServiceRequest geometryServiceRequest = new GeometryServiceRequest() { text = string.Empty, geometry = new double[] { x, y }, geometryType = ESRIGeometryTypes.esriGeometryPoint, inSR = null, spatialRel = ESRISpatialRelationship.esriSpatialRelWithin, relationParam = string.Empty, where = string.Empty, returnCountOnly = false, returnIdsOnly = false, returnGeometry = false, outFields = null, f = "json" }; string payload = RequestPayload(geometryServiceRequest); System.Net.HttpWebResponse response = AGOLRestHandler.RequestAndResponseHandler.HttpWebGetRequest(requestURL + payload, "http://startups.maps.arcgis.com"); string json = AGOLRestHandler.RequestAndResponseHandler.DeserializeResponse(response.GetResponseStream()); _geometryResponseObject = AGOLRestHandler.RequestAndResponseHandler.GetObjectFromJSON(json, DataContractsEnum.GeometryResponse) as AGOLRestHandler.GeometryResponse; }