string tokenurl =
string.Format("https://myserver/arcgis/tokens?request=getToken&username={0}&password={1}&timeout={2}",
username, password, timeout);
tring tokenurl =
string.Format("http://lidar.gis.halff.com/Centaur/tokens/gettoken.html?request=getToken&username={0}&password={1}&timeout={2}",
username, password, timeout); 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));
}MessageBox.Show(theToken);

string tokenurl =
string.Format("http://lidar.gis.halff.com/Centaur/tokens/gettoken.html?request=getToken&username={0}&password={1}&t...}",
username, password, timeout);
string tokenurl =
string.Format("http://lidar.gis.halff.com/Centaur/tokens?request=getToken&username={0}&password={1}&timeout={2}",
username, password, timeout);
I tried the code posted here in this article but the code doesn't compile as Silverlight is Async and the WebRequest class does not support :GetResponse().
public void GetTokenAsync()
{
WebClient wc = new WebClient();
wc.UploadStringCompleted += (s, e) => MessageBox.Show(e.Error == null ? "Token = " + e.Result : "Error = " + e.Error.Message);
wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
string data = EncodeParameter("request", "getToken");
data += EncodeParameter("username", "staff1");
data += EncodeParameter("password", "staff1#1");
wc.UploadStringAsync(new Uri("http://50.19.243.162/arcgis/tokens/"), data);
}
private static string EncodeParameter(string name, string value)
{
return name + "=" + System.Windows.Browser.HttpUtility.UrlEncode(value) + "&";
}
can I assume the origional poster was using WPF to get a token via code and the example in this blog post is about WPF and Rex's comment on 6-Mar-2011 confirms that this will not work in Silverlight.
http://blogs.esri.com/Dev/blogs/silv...-services.aspx
When it is time to move to production, the plan is to use HTTPS.
If generating a token in Silverlight, the user name and password will be visible on the client, even over an HTTPS connection. In most cases, you'll want to store credentials in a server-side resource (for example, proxy page) and direct requests for token secured services through the server resource.