GeodatabaseSyncTask.CreateAsync With credentials always return 401

04-06-2017 06:47 AM
New Contributor III


When I try to create a GeodatabaseSyncTask with credentials it Always returns 401 unauthorized, even when the credentials are right. Here is the code that I'm using right now:

System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(userName, passWord, domain);

            var credential = new ArcGISNetworkCredential
                Credentials = networkCredential,
                ServiceUri = featureURI
            GeodatabaseSyncTask gdbTask = await GeodatabaseSyncTask.CreateAsync(featureURI, credential);

I don't know if my code is wrong, but I've tried it on iOS (API100.0) and old .NET api and it worked fine!

0 Kudos
3 Replies
New Contributor III

Here is code that I used. Not 100% sure if you need both of the last two lines or not, but it should get you close enough that you can debug:

var featureServiceUri = new Uri(;

var credential = new ArcGISTokenCredential();
credential.ServiceUri = new Uri("");
credential.Password = Password;
credential.UserName = Username;

var creds = await AuthenticationManager.Current.GenerateCredentialAsync(credential.ServiceUri, Username, Password);

var gdbSyncTask = await GeodatabaseSyncTask.CreateAsync(featureServiceUri, creds);

// define an extent for the features to include
// Whole world extent, but project to web map before we can use it
var env = new Envelope(-179.99, -89.99, 179.99, 89.99, new SpatialReference(4326));
var extent = GeometryEngine.Project(env, new SpatialReference(102100)).Extent;

// get the default parameters for generating a geodatabase
var generateGdbParams = await gdbSyncTask.CreateDefaultGenerateGeodatabaseParametersAsync(extent);

// set the sync model to per layer
generateGdbParams.SyncModel = SyncModel.Geodatabase;

// do not return attachments
generateGdbParams.ReturnAttachments = false;

// create the generate geodatabase job, pass in the parameters and an output path for the local geodatabase
var generateGdbJob = gdbSyncTask.GenerateGeodatabase(generateGdbParams, GeodatabaseFile);

// handle the JobChanged event to check the status of the job
generateGdbJob.JobChanged += OnGenerateGdbJobChanged;

// start the job and report the job ID
var x = await generateGdbJob.CheckStatusAsync();
var zz = generateGdbJob.GetResultAsync();
0 Kudos
New Contributor III

Does it really work for you? Because I've tried to get the credentials just like your code and got the same error.

0 Kudos
New Contributor III

It really does work. Not other suggestions other than checking to make sure your URLs are correct.

0 Kudos