Use ExportTileCacheTask catch a exception

1979
12
06-21-2017 05:35 AM
xiaoguangyan
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)
0 Kudos
12 Replies
AnttiKajanus1
Occasional Contributor III

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. 

0 Kudos
xiaoguangyan
New Contributor III

Hi, Antti

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

0 Kudos
AnttiKajanus1
Occasional Contributor III

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).

0 Kudos
AnttiKajanus1
Occasional Contributor III
0 Kudos
xiaoguangyan
New Contributor III

Thanks, Antti.

0 Kudos
xiaoguangyan
New Contributor III
0 Kudos
AnttiKajanus1
Occasional Contributor III

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?  

0 Kudos
xiaoguangyan
New Contributor III

Yes, Antti, I can sign in without problems

0 Kudos
AnttiKajanus1
Occasional Contributor III

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;
        }
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos