ApplyEditsAsync returns no results... sometimes...

170
4
04-05-2024 04:27 AM
PierreMasson
Occasional Contributor

Hi,

We're building an app with Arcgis Maps SDK .Net. I can edit geometry, like move a point no problem. But when I try to create a new point using AddFeatureAsync and ApplyEditAsync sometimes it works perfectly and all of a sudden, the ApplyEdit call returns no results. No mater what when the probleme occurs it keeps happening for a long time.. Then later on I try again and it works perfectly.

I tried to diagnose the problem using Fiddler to see what is sent to the Feature Service and when no results are returned, Nothing appears in Fiddler. It's like the SDK is not sending my request at all. 

Here's the code. The FeatureTable is loaded..

await ((ServiceFeatureTable)entity.Feature.FeatureTable).AddFeatureAsync(entity.Feature);
IReadOnlyList<FeatureTableEditResult> results = await ApplyEditsAsync(true);

Here results.Count = 0...

Why? How can I diagnose that further. Please help.

 

Tags (1)
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor

Could your ApplyEdits be wrapped in a try-catch? Can you see if exception has message/details? Could the new feature be rejected by server because of geometry (has or lack of m/z-value, spatial reference, outside layer extent) or attributes (any unspecified required fields, data type mismatch, domain errors, or perhaps constraint rule violation)?

 

Few other things you can try:

 

After addFeatureAsyc, check getAddedFeaturesCountAsync to ensure new feature was added.

 

Before applyEdits subscribe to ArcGISHttpClientHandler events: HttpBeginRequest and HttpResponseEnd.

You can check request URI on Begin to ensure an /applyEdits request was made. And read content as string on End to ensure an appropriate server response in JSON was received. This should provide objectid or globalid

when successful or an error code/message. If the message is the generic unable to complete, you can check server logs for verbose message if you have access to the server.

PierreMasson
Occasional Contributor

Hi,

Thank you for the suggestions. Here's the result:

  • AddFeatureAsync & ApplyEditAsync are not raising any exception
  • After calling AddFeatureAsync, I called getAddedFeaturesCountAsync and it returned 1 like it should.
  • I added subscription to ArcGISHttpClientHandler.HttpRequestBegin & ArcGISHttpClientHandler.HttpResponseEnd before calling ApplyEditsAsync and no event are raised.

It's like ApplyEditAsync does nothing at all... The returned Result count is 0

Here's my code.

await ((ServiceFeatureTable)entity.Feature.FeatureTable).AddFeatureAsync(entity.Feature);

long numAdded = await ((ServiceFeatureTable)entity.Feature.FeatureTable).GetAddedFeaturesCountAsync();

ArcGISHttpClientHandler.HttpRequestBegin += ArcGISHttpClientHandler_HttpRequestBegin;
ArcGISHttpClientHandler.HttpResponseEnd += ArcGISHttpClientHandler_HttpResponseEnd;

IReadOnlyList<FeatureTableEditResult> results = await ((ServiceFeatureTable)this.Table).ServiceGeodatabase.ApplyEditsAsync();

ArcGISHttpClientHandler.HttpRequestBegin -= ArcGISHttpClientHandler_HttpRequestBegin;
ArcGISHttpClientHandler.HttpResponseEnd -= ArcGISHttpClientHandler_HttpResponseEnd;

 

0 Kudos
PierreMasson
Occasional Contributor

Ok I found My problem. 

this:
await ((ServiceFeatureTable)entity.Feature.FeatureTable).AddFeatureAsync(entity.Feature);

is using the FeatureTable of the Feature to add the feature.

While this

((ServiceFeatureTable)this.Table).ServiceGeodatabase.ApplyEditsAsync();

uses a Reference to the table I stocked in the class doing the operation. Somewhere thing gor mixed up and it looke like it's not the same instance of the table. 

so if I do AddFeatureAsync & ApplyEdits with the same table it works everytime.

Sorry this was a problem located at 18 inches from the screen.

0 Kudos
JenniferNery
Esri Regular Contributor

Thanks for following-up and sharing with us the root of the problem. I am curious to know how the table was created and why ServiceGeodatabase do not see this edit.  

If you loaded the feature service from a webmap or called ServiceGeodatabase.getTable() to create the ServiceFeatureTable, the ServiceFeatureTable will have a ServiceGeodatabase property. You'd see ServiceGeodatabase.connectedTables include this table. Your feature should have access to the same ServiceGeodatabase. If however, you used a ServiceFeatureTable constructor, then the table will not have a ServiceGeodatabase.

You can add a check to ServiceGeodatabase.hasLocalEdits() or ServiceFeatureTable.hasLocalEdits(), before calling the appropriate applyEdits. If this returns false, there are no edits to send to server.

It is best to use ServiceGeodatabase, for these reasons: https://developers.arcgis.com/net/edit-features/apply-edits/

if (feature.FeatureTable is ServiceFeatureTable sft && sft.ServiceGeodatabase is ServiceGeodatabase sgdb)
{
    if (sgdb.HasLocalEdits())
    {
        await sgdb.ApplyEditsAsync();
    }
}

 

 

 

0 Kudos