Relationship Query (API v3.2) is not compatible with ArcGIS Server 10.2 REST services

1472
2
01-30-2014 06:26 AM
GreggCornetski
New Contributor III
I've been unable to successfully complete a relationship query of my feature services using 1) the Get Related Records tool (aka Query Related Records Tool) in SL 3.2 Viewer and 2) using the SL API v3.2.

My feature services run on ArcGIS Online hosted services account for developers. Note ESRI runs these ArcGIS Online subscription and developer accounts on ArcGIS Server v10.21.

I believe the problem is that the query classes in the SL 3.2 API Tasks library cannot handle a new JSON syntax returned by the queryRelatedRecords REST operation on AGS v10.21.

Here is a sample relationship query that successfully executes on an ESRI sample server service which ESRI happens to run on ArcGIS Server v10.0. 

queryTask = new QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0");
queryTask.ExecuteRelationshipQueryCompleted += QueryTask_ExecuteRelationshipQueryCompleted;

//Relationship query
RelationshipParameter relationshipParameters = new RelationshipParameter()
{
    ObjectIds = new int[] { 113880 },
    OutFields = new string[] { "*" },
    RelationshipId = 3,
    ReturnGeometry = false
};

queryTask.ExecuteRelationshipQueryAsync(relationshipParameters);

void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
{
    RelationshipResult pr = e.Result;
    if (pr.RelatedRecordsGroup.Count == 0)
    {
 //RelatedRecordsGroup.Count is always zero when query is executed on ArGIS Server 10.21
 //But when executed against ArcGIS Server 10.0, RelatedRecordsGroup does contain the related records 
    }
    else
    {
 foreach (var pair in pr.RelatedRecordsGroup)
 {
     //Do something
 }
    }
}


When I execute the same code on my feature service which runs on ArcGIS Online hosted feature services v10.21, the related records group count is always zero. Interestingly, no matter if I query the ESRI sample service or my own AGO account service, in Fiddler the REST queryRelatedRecords query is always valid AND the response DOES contain the related records. However, when I query my services on v10.21 the related records in the JSON response never make it into the ArcGIS Silverlight API query objects.

I closely examine the requests and responses in Fiddler. When I query the sample service on ArcGIS Online v10.0, the JSON response format is:

{"fields":[...],"relatedRecordGroups":[{"objectId":1,"relatedRecords":[...]}]}


However, when I query my feature service running on ArcGIS Online v10.21, the JSON response format is

{"fields":[...],"relatedRecordGroups":[{"OBJECTID":1,"relatedRecords":[...]}]}


Notice the subtle difference in JSON syntax. From AGS v10.0 the related record group object is identified by the object ID attribute.In AGS v10.0 the object ID name is camel-cased: "objectId". However, in AGS v10.21 the object ID attribute is all-caps: "OBJECTID".

I suspect the query classes in the ArcGIS Silverlight API v3.2 are case-sensitive to the JSON response. I think the query classes expect the relatedRecordGroups to be identified by the camel-case object ID attribute. At AGS 10.2 ESRI seems to have changed the same attribute to the all-caps "OBJECTID". According to my tests, the query classes are unable to de-serialize the related records in the JSON response presumably because the API expects the related records groups to be identified by a camel-cased object ID, rather than an all-caps object ID.

This "bug" seems to make it impossible to use the ArcGIS SL API v3.2 to successfully complete a relationship query on AGS v10.21.
0 Kudos
2 Replies
GreggCornetski
New Contributor III
I have since used Fiddler to tamper with the queryRelatedRecords response from ArcGIS Server 10.2.1. I set a breakpoint on the response. In the JSON response I changed the "OBJECTID" attribute to "objectId" (in JSON snippet shown below).

{"fields":[...],"relatedRecordGroups":[{"OBJECTID":1,"relatedRecords":[...]}]} 


I resumed and stepped through the C# code. With that change, the RelationshipResult now contains the related records.

This seems to confirm that ESRI has changed the syntax of the relatedRecordGroups JSON object at least at v10.2.1 and this syntax is not handled by the query classes in the ArcGIS Silverlight v3.2 Tasks library.
0 Kudos
DaveOrlando
Occasional Contributor III

very interesting, thanks for the post.

I had to restore my 10.1 Server because of intermittent QueryTask failures on my 10.2.2 trial (using Silverlight API 3.1)

could this be a similar issue? Server Logs were saying failure to convert string 12345.123 to int. but it should be a string and stay a string throughout, and I have no idea what process is trying to convert it into an int.

I try to understand the technology behind all of this but get lost when queries get jammed through so many different formats (JSON syntax as you mention).......

0 Kudos