I'm having trouble programmatically retrieving a token to access secure services. I have used several examples and they all give me the same result, so I'm assuming the issue is with my request string. The URL of the site where I manually retrieve tokens is http://lidar.gis.halff.com/Centaur/tokens/gettoken.html. So how do I put that in this:string tokenurl =
string.Format("https://myserver/arcgis/tokens?request=getToken&username={0}&password={1}&timeout={2}",
username, password, timeout);
form to get a token?This is what I have which is obviously wrong:tring tokenurl =
string.Format("http://lidar.gis.halff.com/Centaur/tokens/gettoken.html?request=getToken&username={0}&password={1}&timeout={2}",
username, password, timeout);
This is the code example I'm currently using from the ESRI Silverlight/WPF Blog: ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer()
{
Url = "http://barn.halff.com/Centaur/rest/services/Lubbock/Lubbock_SW_WebMap_v10b/MapServer",
ID = "Lubbock SW"
};
layer.InitializationFailed += layer_InitializationFailed;
ConfigureLayerWithToken(layer);
void layer_InitializationFailed(object sender, EventArgs e)
{ }
private void ConfigureLayerWithToken(ArcGISDynamicMapServiceLayer layer)
{
string tokenurl =
string.Format("http://lidar.gis.halff.com/Centaur/tokens/gettoken.html?request=getToken&username={0}&password={1}&timeout={2}",
username, password, timeout);
WebClient tokenService = new WebClient();
tokenService.DownloadStringCompleted += (sender, args) =>
{
theToken = args.Result;
MessageBox.Show(theToken);
layer.Token = theToken;
string originalUrl = layer.Url;
if (Map.Layers.Contains(layer))
{
layer.Url = null;
layer.Url = originalUrl;
}
else
Map.Layers.Add(layer);
};
tokenService.DownloadStringAsync(new Uri(tokenurl));
}
Any help as to what I'm doing wrong would be greatly appreciated, Thanks!