Use ExportTileCacheTask catch a exception

623
12
06-21-2017 05:35 AM
Highlighted
New Contributor III

when I execute "await ExportTileCacheTask.CreateAsync(basemap.Source);" catch a Invalid response: Service does not support tile export. I use map in https://www.arcgis.com/home/group.html?owner=esri&title=Tiled%20Basemaps&start=11&q  for export also catch this exception

Tags (1)
Reply
0 Kudos
12 Replies
Highlighted
Regular Contributor II

Hi,

Can you give the exact code / url that you are using? Following seems to work without any problems.

var task = await ExportTileCacheTask.CreateAsync(
    new Uri("https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Street_Map/MapServer"));

Remember that you shouldn't use the service "For export" services as your basemaps, they are intended to be used for taking tiles offline and not visualization. 

Reply
0 Kudos
Highlighted
New Contributor III

Hi, Antti

I just tested your uri, it will catch the "Token Required" exception

Reply
0 Kudos
Highlighted
Regular Contributor II

That is expected if you haven't signed in to ArcGIS Online since the export tiles feature is available to subscribed users (operation doesn't consume credits but you have to be signed in to have a access to it).

Reply
0 Kudos
Highlighted
Regular Contributor II
Reply
0 Kudos
Highlighted
New Contributor III

Thanks, Antti.

Reply
0 Kudos
Highlighted
New Contributor III
Reply
0 Kudos
Highlighted
Regular Contributor II

Can you sign into the ArcGIS Online with your credentials? If you sign in to https://www.arcgis.com/home/signin.html does the authentication go through without any problems?  

Reply
0 Kudos
Highlighted
New Contributor III

Yes, Antti, I can sign in without problems

Reply
0 Kudos
Highlighted
Regular Contributor II

Can you try if this works? Just change it to use your credentials. 

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(CreateKnownCredentials);
            Initialize();
        }

        private async void Initialize()
        {
            try
            {
                var task = await ExportTileCacheTask.CreateAsync(new Uri("https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Street_Map/MapServer"));
            }
            catch (Exception ex)
            {
                // Something unexpected happened, handle properly
                MessageBox.Show(ex.Message);
            }
        }

        private string _username = "abcd";
        private string _password = "1234";

        private async Task<Credential> CreateKnownCredentials(CredentialRequestInfo info)
        {
            // If this isn't the expected resource, the credential will stay null
            Credential knownCredential = null;

            try
            {

                // Create a credential for this resource
                knownCredential = await AuthenticationManager.Current.GenerateCredentialAsync
                                        (info.ServiceUri,
                                         _username,
                                         _password,
                                         info.GenerateTokenOptions);
            }
            catch (Exception ex)
            {
                // Report error accessing a secured resource
                MessageBox.Show("Access to " + info.ServiceUri.AbsoluteUri + " denied. " + ex.Message, "Credential Error");
            }

            // Return the credential
            return knownCredential;
        }
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Reply
0 Kudos