get token and show layer in ArcGis Runtime SDK for .NET

if  you  have  to  add a secure layer  from the  ArcGIS server  ,at  first  you have  to  get  token  for  this server

so  first  step  is to  send a request to  server  and  get  token.

for  that  i  always  use  The System.Net.WebRequest  for  cerating  a request  and  sending  it  to  server

the MapSettign is  a class  the  contains The UserName  and  Password  for  getting  the  Token


    public partial class MapSetting
        public int Id { get; set; }
        public string Provider { get; set; }
        public Nullable IsSecure { get; set; }
        public string Token { get; set; }
        public string EnvelopExtent { get; set; }
        public string WmsUrl { get; set; }
        public Nullable X { get; set; }
        public Nullable Y { get; set; }
        public Nullable Zome { get; set; }
        public Nullable Scale { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string TokenUrl { get; set; }
        public string WmsLayerNames { get; set; }
        public string BingKey { get; set; }


 private async void LoadSecureLayer(DAL.Model.MapSetting setting)
            var GetTokenurl = setting.TokenUrl + "?request=getToken&username=" + setting.UserName + "&password=" + setting.Password + "&expiration=30";
            System.Net.WebRequest request = System.Net.WebRequest.Create(GetTokenurl);
            System.Net.WebResponse response = request.GetResponse();
            System.IO.Stream responseStream = response.GetResponseStream();
            System.IO.StreamReader readStream = new System.IO.StreamReader(responseStream);
            var theToken = await readStream.ReadToEndAsync();
            var layer = new ArcGISDynamicMapServiceLayer(new Uri(setting.WmsUrl));
            layer.ID = "network";
            layer.Token = theToken;
            await mapview.SetViewAsync(layer.FullExtent);


after  geting  token you  have to  add this  tken to your layer

   layer.Token = theToken;

this  line  do that.

I  hope  this article  will  be usefull  for  you.

  • Hi. What is the type of the token that is generated by the ArcGIS? is it the JWT toke?