Select to view content in your preferred language

Serious issues for feature layers, data is getting deleted from ArcSDE.

2730
10
02-24-2011 08:04 PM
SanajyJadhav
Deactivated User
Guys,

I am in serious trouble. I am adding featurelayers to the my application. These feature layers come from the featureservice.

The layers are getting added fine, they can be viewed in the application. But, when I use any task like Identify on any of the layers in the application, the data used in featureservice is getting deleted from the SDE Feature Dataset. This is driving me crazy.

Below are the steps I am taking to add the featurelayer.

1.  Create new instance of ArcGISDynamicLayer and initialize it.

 
ArcGISDynamicMapServiceLayer otherFeatBaseMapSrvc = new ArcGISDynamicMapServiceLayer();
            otherFeatBaseMapSrvc.Url = currentApps.WebconfigVrbls.OtherFeaturesBaseMapSrvc;
            otherFeatBaseMapSrvc.ID = "Other Features Map Service";
            otherFeatBaseMapSrvc.Initialized += new EventHandler<EventArgs>(BaseMapSrvc_Initialized);
            otherFeatBaseMapSrvc.InitializationFailed += new EventHandler<EventArgs>(BaseMapSrvc_InitializationFailed);

            //if this map service is not initialized, then manually initialize it.
            if (otherFeatBaseMapSrvc.IsInitialized == false)
            {
                otherFeatBaseMapSrvc.Initialize();    
        }


2. In the initialized event, access the layer info object and create FeatureLayer object

void BaseMapSrvc_Initialized(object sender, EventArgs e)
        {
            ArcGISDynamicMapServiceLayer lyr = sender as ArcGISDynamicMapServiceLayer;

            //get layer info array
            LayerInfo[] lyrInfoArray = lyr.Layers;

            if (lyrInfoArray != null)
            {
                //iterate thru each layer info and create feature service url for each of the layer by taking it's ID
                for (int i = 0; i < lyrInfoArray.Length; i++)
                {
                    LayerInfo lyrInfo = lyrInfoArray;
                    string featureLyrURL = lyr.Url.Replace("MapServer", "FeatureServer") + "/" + lyrInfo.ID;

                    //set  feature layer using above url  
                    FeatureLayer featLyr = new FeatureLayer();
                    featLyr.ID = lyrInfo.Name;
                    featLyr.Mode = FeatureLayer.QueryMode.OnDemand;
                    featLyr.Url = featureLyrURL;
                    featLyr.InitializationFailed += new EventHandler<EventArgs>(EditFeatLyr_InitializationFailed);
                    featLyr.Initialized += new EventHandler<EventArgs>(EditFeatLyr_Initialized);

                    if (featLyr.IsInitialized == false)
                    {
                        featLyr.Initialize();
                    }
                }
            }           
        }


3. In the initialized event of the feature layer, add it to the map.

void EditFeatLyr_Initialized(object sender, EventArgs e)
        {
            //get reference to the feature layer that raised the event 
            FeatureLayer fl = sender as FeatureLayer;

            //add this feature layer to the map.
            currentApps.MapXaml.MyMap.Layers.Add(fl);

            //add this feature layer to application level collection object
            currentApps.AllMapServicesCollection.Add(fl); 
        }


This is very serious issue for us. I am not getting how to fix it. If I add the normal map services in the code behind, everything works normal.Whenever, this featureservice comes into picture, problem rises.

Please help me on this issue.

Thanks,
Sanjay.
0 Kudos
10 Replies
DominiqueBroux
Esri Frequent Contributor
the data used in featureservice is getting deleted from the SDE Feature Dataset. This is driving me crazy.

Do you mean that the data are definitively lost on the server side? (I can understand you get crazy!)
0 Kudos
JenniferNery
Esri Regular Contributor
This sounds serious.

However, I am not able to repro it.

I tried the following code. It is close to what you have, except that I find no reason for the check if layer is already initialized since the check is done at layer creation where layer has not yet been added to the map. I also set Extent so I can define SpatialReference, but you can run the sample without it. I am using SampleServer3. I also added UpdateCompleted event to show in your OutputWindow how many features exist in the feature layer for that given extent (since the layers are OnDemand mode).

XAML-Code:
    <Grid x:Name="LayoutRoot" Background="White">
 <esri:Map x:Name="MyMap">
  <esri:Map.Extent>
   <esri:Envelope XMin="-118.207462406372" YMin="33.5439110882534" XMax="-117.255773795146" YMax="34.8265277847467" >
    <esri:Envelope.SpatialReference>
     <esri:SpatialReference WKID="4326"/>
    </esri:Envelope.SpatialReference>
   </esri:Envelope>
  </esri:Map.Extent>
 </esri:Map>
 <Button Content="add layers" VerticalAlignment="Top" HorizontalAlignment="Center" Click="Button_Click"/>
</Grid>


Code-Behind:
private void Button_Click(object sender, RoutedEventArgs e)
{
 ArcGISDynamicMapServiceLayer dynamicLayer = new ArcGISDynamicMapServiceLayer()
 {
  Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer"
 };
 dynamicLayer.Initialized += dynamicLayer_Initialized;
 dynamicLayer.Initialize();
}

void dynamicLayer_Initialized(object sender, System.EventArgs e)
{
 ArcGISDynamicMapServiceLayer layer = sender as ArcGISDynamicMapServiceLayer;
 MyMap.Layers.Add(layer);
 string featureService =layer.Url.Replace("MapServer", "FeatureServer");
 foreach (var l in layer.Layers)
 {
  FeatureLayer featureLayer = new FeatureLayer()
  {
   ID = l.Name,
   Mode = FeatureLayer.QueryMode.OnDemand,
   Url = string.Format("{0}/{1}",featureService, l.ID)
  };
  featureLayer.UpdateCompleted += featureLayer_UpdateCompleted;
  featureLayer.Initialized += featureLayer_Initialized;
  featureLayer.Initialize();
 }
}

void featureLayer_UpdateCompleted(object sender, System.EventArgs e)
{
 FeatureLayer layer = sender as FeatureLayer;
 System.Diagnostics.Debug.WriteLine("{0} Graphics Count: {1}", layer.ID, layer.Graphics.Count);   
}

void featureLayer_Initialized(object sender, System.EventArgs e)
{
 FeatureLayer layer = sender as FeatureLayer;
 MyMap.Layers.Add(layer);
}
0 Kudos
SanajyJadhav
Deactivated User
Thanks Jenn for the reply.

It seems that my flow to add the featrue layers is not correct.

I went through your code and found few differences;
You have added dynamic service layer in your void dynamicLayer_Initialized to the map but I have not. Can you please tell me the reason for this? I mean, since we are adding feature layer from the feature service, does it become necessary to add the base map service also to the application?

Second thing is, you have not checked instantiation of the dynamic map service that exposes the feature service.Ok, this I understand.

Apart from that, I could not spot any difference. I would try with your approach and let you know my results.

And Domnique, yes, the features are getting physically deleted on the server side. The feature dataset just becomes empty.

Ok, I would change my code and put my results on this post.

Thx,
Sanjay J.
0 Kudos
JenniferNery
Esri Regular Contributor
Oh cuz you called it your base map service, I assumed you were using the ArcGISDynamicMapServiceLayer as base layer, this is why I added it as first layer of the map. And since you were doing a check if layer had been initialized, I thought you expect it to already be initialized by maybe adding the layer to your map. So the main function of your ArcGISDynamicMapServiceLayer is to determine the sub layers and create FeatureLayers against them? This should not be a problem. From my code snippet, you can remove the part where the ArcGISDynamicMapServiceLayer is added to your map. I think other than those two discrepancies, your code and mine are identical and I do not see the features deleted from the layer by doing so.
0 Kudos
SanajyJadhav
Deactivated User
Sorry Jenn, my bad. I should have explained it more properly.

Thanks for replying. I am gonna do more investigation on this tomorrow as I am on leave today.

Regards,
Sanjay.
0 Kudos
SanajyJadhav
Deactivated User
Hi,

I have started again to work on this issue and seeing the same problem.

I am adding the feature layers from the featureservice in code behind.Adding them in xaml is not an option for us.And, whenever I fire any query (attribute or spatial) on it. data is physically getting is deleted from our sde.

I have been doing some troubleshooting and not able to fix it. I am pasting my code below.

Can anybody please help me on this issue? I would really appreciate it.

[PHP]
                // site intent feature layer

                FeatureLayer SiteIntentFeatLyr = new FeatureLayer();
                SiteIntentFeatLyr.ID = "Site_Intent_Area";
                SiteIntentFeatLyr.Mode = FeatureLayer.QueryMode.OnDemand;
                SiteIntentFeatLyr.Url = "http://srvrName/ArcGIS/rest/services/Plant_Infra_Edit/FeatureServer/10";
                SiteIntentFeatLyr.InitializationFailed += new EventHandler<EventArgs>(EditFeatLyr_InitializationFailed);
                SiteIntentFeatLyr.Initialized += new EventHandler<EventArgs>(EditFeatLyr_Initialized);

                if (SiteIntentFeatLyr.IsInitialized == false)
                {
                    SiteIntentFeatLyr.Initialize();
                }[/PHP]

Code for feature layer initialization :

[PHP]
void EditFeatLyr_Initialized(object sender, EventArgs e)
{
//get reference to the feature layer that raised the event
                FeatureLayer fl = sender as FeatureLayer;

                //add this feature layer to the map.
                currentApps.MapXaml.MyMap.Layers.Add(fl);

                //add this feature layer to application level collection object
                currentApps.AllMapServicesCollection.Add(fl);
               
                .....
}

[/PHP]

Once the layers are added, I can see them on the map.But when I execute any query against any feature layer, data is getting deleted.

I tried passing the featureservice url and map service url to the constructor of the query task, but no use.

Thanks in advance,
Sanjay.
0 Kudos
JenniferNery
Esri Regular Contributor
Hi Sanjay,

I am unable to reproduce this issue. Kindly see attached project. I tried to do the same work flow.
1 - Initialize ArcGISDynamicMapServiceLayer
2 - Create and add FeatureLayers
3 - Run Spatial Query on these FeatureLayers

Maybe you can set FeatureLayer.AutoSave to false at creation. This is true by default. It might be that somewhere in your code, you call a layer.Graphics.Clear() or layer.ClearGraphics(). This local change gets pushed directly to your service unless AutoSave is false and you did not call SaveEdits() explicitly.

Any new information is welcome. Please feel free to update the attached project so we can get it to the same state as your project.

Thanks.
0 Kudos
SanajyJadhav
Deactivated User
Thanks Jenn for your sample project.

I would work on it and see if I can reproduce my issue with it.As per my memory, I have not called anywhere layer.Graphics.Clear() or layer.ClearGraphics().But, I will see from that perspective.

Thanks again for your continuous help on this issue.

Sanjay.
0 Kudos
SanajyJadhav
Deactivated User
Jenn,

You saved my life.
It might be that somewhere in your code, you call a layer.Graphics.Clear() or layer.ClearGraphics(). This local change gets pushed directly to your service unless AutoSave is false and you did not call SaveEdits() explicitly.


This was exactly what I was doing.Before executing any query, I was clearing existing graphics if any.It slept out of my mind that, FeatureLayer is type of the GraphicsLayer.So, it was deleting the features from it.

Any ways, all is set now.Thanks a ton to you for pointing me in the right direction. I really appreciate your help.

-Sanjay.
0 Kudos