I'm trying to search fields from the map (uri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2"). The web page reveals that it contains many fields such as the following:
Fields:
However, when I try to use the following code to perform the search, I always get nothing (findResults.Results always null). Can someone please help me to identify where it went wrong? Many thanks (mapUri is the map Uri above).
private async Task MyQuery()
{
try
{
resultsGrid.Visibility = Visibility.Collapsed;
resultsGrid.ItemsSource = null;
FindTask findTask = new FindTask(mapUri);
var param = new FindParameters()
{
LayerIDs = new List<int> { 0, 1, 2 },
SearchFields = new List<string> { "STATE_NAME" },
ReturnGeometry = true,
SpatialReference = MyMapView.SpatialReference,
SearchText = "Colorado"
};
var findResults = await findTask.ExecuteAsync(param);
if ((findResults != null) && (findResults.Results != null) && (findResults.Results.Count > 0))
{
resultsGrid.ItemsSource = findResults.Results;
resultsGrid.Visibility = Visibility.Visible;
}
else
MessageBox.Show("Found Nothing!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Find Sample");
}
}