Select to view content in your preferred language

Use ExportTileCacheTask catch a exception

2385
12
06-21-2017 05:35 AM
xiaoguangyan
Emerging Contributor

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
Deactivated User

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
Emerging Contributor

Hi, Antti

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

0 Kudos
AnttiKajanus1
Deactivated User

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
xiaoguangyan
Emerging Contributor

Thanks, Antti.

0 Kudos
xiaoguangyan
Emerging Contributor
0 Kudos
AnttiKajanus1
Deactivated User

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
Emerging Contributor

Yes, Antti, I can sign in without problems

0 Kudos
AnttiKajanus1
Deactivated User

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