Can´t load data from feature-service

1673
3
03-14-2018 12:58 AM
CarstenSchumann
Occasional Contributor

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.

0 Kudos
3 Replies
dotMorten_esri
Esri Notable Contributor

try calling "await table.LoadAsync()" before you perform your query.

0 Kudos
CarstenSchumann
Occasional Contributor

This seems to push some light into the aactual problem, as I now get a HttpRequestException "The remote certificate is invalid according to the validation process."

0 Kudos
dotMorten_esri
Esri Notable Contributor

I'm guessing you're using an HTTPS connection to a server with an invalid SSL certificate. You'd need to either fix the certificate, or move to non-https.

0 Kudos