Select to view content in your preferred language

GeodatabaseSyncTask.CreateAsync With credentials always return 401

1507
3
04-06-2017 06:47 AM
TércyoStorck1
Occasional Contributor

Hello,

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
KeithGemeinhart1
Regular Contributor

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(https://services6.arcgis.com/xxxxxx/arcgis/rest/services/zzzzzz/FeatureServer);

var credential = new ArcGISTokenCredential();
credential.ServiceUri = new Uri("https://services6.arcgis.com/xxxxxx/arcgis/rest/services");
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
TércyoStorck1
Occasional Contributor

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
KeithGemeinhart1
Regular Contributor

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

0 Kudos