private byte[] QueryByExtentHandler(NameValueCollection boundVariables,
                                            JsonObject operationInput,
                                            string outputFormat,
                                            string requestProperties,
                                            out string responseProperties)
        {
            responseProperties = null;

            if (networkDataset == null)
            {
                throw new NullReferenceException("Could not access the network dataset.");
            }

            if (!operationInput.TryGetString("Extent", out var envelopeString))
            {
                throw new ArgumentNullException("Extent is invalid.");
            }
            var coords    = envelopeString.Split(';');
            var minCoords = coords[0].Split(',');
            var maxCoords = coords[1].Split(',');

            double.TryParse(minCoords[0].Trim(), out var minX);
            double.TryParse(minCoords[1].Trim(), out var minY);
            double.TryParse(maxCoords[0].Trim(), out var maxX);
            double.TryParse(maxCoords[0].Trim(), out var maxY);

            // Find features in envelope
            IEnvelope env = new EnvelopeClass();

            env.PutCoords(minX, minY, maxX, maxY);
            ISpatialFilter spatialFilter = new SpatialFilter();

            spatialFilter.Geometry   = env;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            // Add selected features OID into LongArray
            ILongArray     oIDs    = new LongArray();
            IFeatureCursor fCursor = streetFC.Search(spatialFilter, true);
            IFeature       feature = fCursor.NextFeature();

            while (feature != null)
            {
                oIDs.Add(feature.OID);
                feature = fCursor.NextFeature();
            }

            // Get the network edges corresponding to the streets and write out information about them

            INetworkQuery    networkQuery = networkDataset as INetworkQuery;
            INetworkJunction fromJunction =
                networkQuery.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;
            INetworkJunction toJunction =
                networkQuery.CreateNetworkElement(esriNetworkElementType.esriNETJunction) as INetworkJunction;

            IEnumNetworkElement networkElements = networkQuery.ElementsByOIDs[streetsSourceID, oIDs];
            INetworkElement     networkElement  = networkElements.Next();
            JSONObject          result          = new JSONObject();
            JSONArray           elementArray    = new JSONArray();
            INetworkEdge        networkEdge;

            while (networkElement != null)
            {
                JSONObject jo = new JSONObject();
                networkEdge = networkElement as INetworkEdge;
                networkEdge.QueryJunctions(fromJunction, toJunction);
                double travelTime = (double)networkEdge.AttributeValue[travelTimeAttributeID];
                jo.AddLong("EdgeID", networkEdge.EID);
                jo.AddLong("FromJunctionID", fromJunction.EID);
                jo.AddLong("ToJunctionID", toJunction.EID);
                jo.AddDoubleEx(costAttributeName, travelTime, 4);
                elementArray.AddJSONObject(jo);
                networkElement = networkElements.Next();
            }
            result.AddJSONArray("NetworkElements", elementArray);

            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }