HimBromBeere

Can´t load data from feature-service

Discussion created by HimBromBeere on Mar 14, 2018
Latest reply on Mar 15, 2018 by mnielsen-esristaff

I followed the samples from ESRI (e.g. this one from GitHub) to enable feature-access to my service and everything worked fine. Next I changed the URL into my own feature-service and provided my crendetials to access that service.

 

So I ended up with the following code:

//var serviceUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0";
var serviceUrl = "https://myhost/arcgis/rest/services/MyService/FeatureServer/0";
ServerInfo serverInfo = new ServerInfo
{
     ServerUri = new Uri(serviceUrl),
     TokenAuthenticationType = TokenAuthenticationType.ArcGISToken,
     TokenServiceUri = new Uri("https://myhost/arcgis/admin/generateToken")
};
AuthenticationManager.Current.RegisterServer(serverInfo);
AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(
     async info =>
          await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, user, password,
               info.GenerateTokenOptions));

var featureTableUri = new System.Uri(serviceUrl);
var table = new ServiceFeatureTable(featureTableUri);
var queryParameters = new QueryParameters { WhereClause = "1 = 1" };
FeatureQueryResult features = await table.QueryFeaturesAsync(queryParameters);

 

When I execute this code I get the following exception on the last line, which doesn´t seem very meaningful to me:

Exception thrown: 'System.InvalidOperationException' in mscorlib.dll
Additional information: Cannot call this method in this context: Object failed to load, unable to execute task.

 

When I set a breakpoint on the GenerateCredentialAsync-line (line 12) I also notice it´s never hit. So I wonder if the challengehandler is even registered correctly and fires the challenge-event appropriately.

Outcomes