I am connection to a Map Service that requires a token and this code works to get the list of layers (where url is something like http://myhost/arcgis/rest/services/MapServer?token=abcdefg😞
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(url + "&f=pjson");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return client.GetAsync("").Result;
}
I then want to go through each layer and add it as a feature layer to a map (where layerUrl looks like http://myhost/arcgis/rest/services/MapServer/5?token=abcdefg)
Uri serviceUri = new Uri(layerUrl);
FeatureLayer layer = new FeatureLayer(serviceUri);
await layer.LoadAsync();
Map.OperationalLayers.Add(layer);
This does not seem to be working. I am getting no errors, but the layer is also showing no features. Is it obvious what I am doing wrong?
Solved! Go to Solution.
As of 200.8.1 you should switch to the following method:
1. Implement IHttpMessageInterceptor
public class MyInterceptor: IHttpMessageInterceptor {
public Task<HttpResponseMessage> SendAsync(HttpMessageInvoker invoker, HttpRequestMessage message, CancellationToken cancellationToken)
{
//work with message here (to add token in RequestUri...)
return invoker.SendAsync(message, cancellationToken);
}
}
2. Resgister your interceptor at ArcGIS initialization:
ArcGISRuntimeEnvironment.Initialize((conf) => {
conf.ConfigureHttp((httpConf)=>httpConf.UseHttpMessageInterceptor(new MyInterCeptor()));
});