I have tried both SDE and shapefile dynamic layers. Every layer that I try is failing in the same way.
If I do the following:
var featureTable = new ServiceFeatureTable() {
ServiceUri = dynamicLayer.ServiceUri + "/dynamicLayer",
Source = dynamicLayer.DynamicLayerInfos[0].Source};
await featureTable.InitializeAsync();
I get an exception -> {"\"key not found\" : "}
at RuntimeCoreNet.Interop.HandleException(Boolean retVal)
at RuntimeCoreNet.CoreFeatureSource..ctor(String path, String featureServiceJson, CoreSpatialReference sr_override)
at Esri.ArcGISRuntime.Data.ServiceFeatureTable.CreateFeatureSource(SpatialReference sr_override)
at Esri.ArcGISRuntime.Data.ServiceFeatureTable.<>c__DisplayClass5f.<InitializeAsyncInternal>b__5d()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
If I take a step back and try to query the service as follows:
QueryTask queryTask = new QueryTask(new Uri(dynamicLayer.ServiceUri + "/dynamicLayer"));
var query = new Query("1=1");
query.ReturnGeometry = true;
query.OutFields.Add("*");
query.Source = dynamicLayer.DynamicLayerInfos[0].Source;
var queryResult = await queryTask.ExecuteAsync(query);
var featureSet = queryResult.FeatureSet;
My FeatureSet has 1 field (the Oid field). The graphics returned have 1 attribute (the Oid field). But I know these layers have other fields that are not being returned. In fact I can load an equivalent service and query in the same fashion in the WPF implementation that I came from and all of the fields are returned. I need to be able to label my SDE layers with more than just the Oid column. I'm certain it's not my data because I can reproduce with any of the shapefiles from the samples. Please tell me this isn't broken!!!
Solved! Go to Solution.
I got it working by setting to null the Fields property of the LayerDataSource:
dynamicLayerInfo.Source = new LayerDataSource { DataSource = dataSource, Fields = null };
By default the Fields property is initialized with an empty Collection which has not the same meaning:
- empty collection --> no field participate to the service
- null --> all fields participate to the service
This raises the question; what is the best default value? An empty collection seems confusing.
You should be using FeatureService endpoint with ServiceFeatureTable and not DynamicLayer.
If you're working with dynamic layers, you can use ArcGISDynamicMapServiceLayer, you can create labeling into the service you are using.
If I execute a query against dynamic layer endpoint, I get all request Attributes so I cannot reproduce this issue. Can you create a reproducer for this so i can give a look?
Hi,
I will try this out with a feature service this morning and see if I get better results.
I am working with ArcGISSynamicMapServiceLayers but the built in labeling doesn't meet my requirements so I am handling labeling myself. That's the big issue though. I need to be able to query the local service for my SDE layer and get back the field information.
In order to reproduce my issue, you can add my query statement from above into the AddShapefileButton_Click handler in the DynamicLayerAddData.xaml.cs from the samples (as I have pasted below). Select any of the sample shapefiles and then look at the query results and see that only the FID field is being identified and returned. For example the world-continents.shp file from the samples shows just FID but also has a CONTINENT, SQKM, and SQMI field that are being ignored.
// Add shapefiles
private async void AddShapefileButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Shapefiles (*.shp)|*.shp";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == true)
{
try
{
List<string> fileNames = new List<string>();
foreach (var item in openFileDialog.SafeFileNames)
{
fileNames.Add(Path.GetFileNameWithoutExtension(item));
}
// Call the add dataset method with workspace type, parent directory path and file names (without extensions)
var dynLayer = await AddFileDatasetToDynamicMapServiceLayer(WorkspaceFactoryType.Shapefile,
Path.GetDirectoryName(openFileDialog.FileName), fileNames);
// Add the dynamic map service layer to the map
if (dynLayer != null)
{
MyMapView.Map.Layers.Add(dynLayer);
}
QueryTask queryTask = new QueryTask(new Uri(dynLayer.ServiceUri + "/dynamicLayer"));
var query = new Query("1=1");
query.ReturnGeometry = true;
query.OutFields.Add("*");
query.Source = dynLayer.DynamicLayerInfos[0].Source;
var queryResult = await queryTask.ExecuteAsync(query);
var featureSet = queryResult.FeatureSet;
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
Have you noticed that you can also read Shapefiles as a features using FeatureLayer and ShapefileFeatureTable?
Yes, I have. I am just using shapefiles for the sake of reproducing the issue. I'm facing the problem when working with an ArcGISDynamicMapServiceLayer that is coming from a local SDE data source. Where is the SDEFeatureTable (maybe coming soon!) ?
I got it working by setting to null the Fields property of the LayerDataSource:
dynamicLayerInfo.Source = new LayerDataSource { DataSource = dataSource, Fields = null };
By default the Fields property is initialized with an empty Collection which has not the same meaning:
- empty collection --> no field participate to the service
- null --> all fields participate to the service
This raises the question; what is the best default value? An empty collection seems confusing.
I have fields! Thank you Sir.
I would have to agree. That default is a bit confusing.
Dominique, is this explanation in the API documentation anywhere? This seems like very important information to leave out! We would not have been able to figure this out had we not found this thread.