I started with an SOI project and attempting to create an interceptor that will take the contents of a map service (layer 1) and kludge some new attributes from some other JSON I have pulled in another request.
Which sample would be closest to what I'd like to attempt?
This YouTube Video is doing what I'd like but is in Java and not C# and I'm having difficulty understanding.
I have a simple SOI.sln setup and just starting to try and fill in the correct areas.
public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName,
string operationInput, string outputFormat, string requestProperties, out string responseProperties)
{
responseProperties = null;
_serverLog.LogMessage(ServerLogger.msgType.infoStandard, _soiName + ".HandleRESTRequest()",
200, "Request received in Sample Object Interceptor for handleRESTRequest");
/*
* Add code to manipulate REST requests here
* https://somearcgisserver.com/somesite/rest/services/test/ServiceNameHere/MapServer/1
* https://some3rdpartyapi.com/v1/realtime
*/
// Find the correct delegate to forward the request too
IRESTRequestHandler restRequestHandler = FindRequestHandlerDelegate<IRESTRequestHandler>();
if (restRequestHandler == null)
return null;
var response = restRequestHandler.HandleRESTRequest(
Capabilities, resourceName, operationName, operationInput,
outputFormat, requestProperties, out responseProperties);
//I think I need to add something here to grab the existing JSON of the mapservice and then kludge the desired attributes into it
if (operationName.Equals("query") && resourceName.Equals("layers/1"))
{
//access the JSON of the map service here
//access the JSON of the 3rd party rest service result
//kludge the two together on the common attribute they share
}
return response;
//return restRequestHandler.HandleRESTRequest(
// Capabilities, resourceName, operationName, operationInput,
// outputFormat, requestProperties, out responseProperties);
}
with json.net you can write similar code
async Task Main()
{
var httpClient = new HttpClient();
var response = await httpClient.GetAsync($"https://.../MapServer/0/query?where=&text=&objectIds=1%2C2%2C4&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=&having=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=&resultRecordCount=&queryByDistance=&returnExtentOnly=false&datumTransformation=¶meterValues=&rangeValues=&quantizationParameters=&f=json");
var r = await response.Content.ReadAsStringAsync();
JObject j = JObject.Parse(r);
JObject alias = (JObject)j["fieldAliases"];
alias.Add("NewField1", new JValue("NewField 1"));
JArray items = (JArray)j["fields"];
items.Add(new JObject()
{
{ "name", "NewField1" },
{ "type", "esriFieldTypeString"},
{ "alias", "NewField 1" },
{ "length", 25 }
});
JArray features = (JArray)j["features"];
foreach (var element in features)
{
//if objectid is 1 field NewField1 add value NewValue
if ((int)element["attributes"]["OID"] == 1)
{
element["attributes"]["NewField1"] = "NewValue";
}
....
}
j.ToString().Dump();
}
ah ha! A response!
Thank you a bunch, I've been looking forward to returning to this asap and this looks promising.