Select to view content in your preferred language

Silverlight Editting in Code Behind

2235
4
01-11-2011 01:46 PM
BradyHustad
Emerging Contributor
Hey all,

I am struggling with an error on trying to add a point in code.  The code is in a viewmodel as I was going to do the adds through a service, but then read all the amazing autoeditting capabilities of the Silverlight API, so I am trying them out... I must be missing something.  The error I get is

Code 400: Unable to Complete Task.

Here is the code, the error I capture on the SaveEditsFailed event.

                    SimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol()
                    {
                        Size = 5,
                        Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle,
                        Color = new SolidColorBrush(Colors.Green)
                    };

                    MapPoint newPoint = new MapPoint(Double.Parse(Longitude), Double.Parse(Latitude));

                    scoutingEvents.SaveEditsFailed += new EventHandler<ESRI.ArcGIS.Client.Tasks.TaskFailedEventArgs>(scoutingEvents_SaveEditsFailed);
                    scoutingEvents.EndSaveEdits += new EventHandler<ESRI.ArcGIS.Client.Tasks.EndEditEventArgs>(scoutingEvents_EndSaveEdits);

                    Graphic newGraphic = new Graphic()
                    {
                        Symbol = markerSymbol,
                        Geometry = mercator.FromGeographic(newPoint)
                    };

                    newGraphic.Attributes.Add("ScoutingEventsId", 1);
                    newGraphic.Attributes.Add("Title", Title);
                    newGraphic.Attributes.Add("Description", Description);

                    if (scoutingEvents.Graphics == null)
                    {
                        scoutingEvents.Graphics = new GraphicCollection();
                    }
                    scoutingEvents.Graphics.Add(newGraphic);
                    scoutingEvents.SaveEdits();

any help is greatly appreciated
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
I assume that scoutingEvents is your FeatureLayer.

Few comments: 
Graphics in FeatureLayer will never be null and cannot be changed once the layer starts to initialize. This is populated based on the features returned by the feature service. Therefore you don't need these lines of code.

if (scoutingEvents.Graphics == null)
{
scoutingEvents.Graphics = new GraphicCollection();
}


You can add to the FeatureLayer Graphics after the layer is Initialized.
if(scoutingEvents.IsInitialized){ //insert code below here }
Graphic newGraphic = new Graphic()
{
Symbol = markerSymbol,
Geometry = mercator.FromGeographic(newPoint)
};

newGraphic.Attributes.Add("ScoutingEventsId", 1);
newGraphic.Attributes.Add("Title", Title);
newGraphic.Attributes.Add("Description", Description);

scoutingEvents.Graphics.Add(newGraphic);


ScoutingEventsId, Title, Description must be the same field names in the feature service and the type must match.
0 Kudos
BradyHustad
Emerging Contributor
Thanks Jennifer,

Yeah, that was just a random attempt at changing behavior or seeing if something wasn't working the way I thought it should, I should have removed the null check before posting, but forgot.  Thanks for catching it!  ScoutingEvents is my FeatureLayer, it is a simple point layer, server on AGS as both MapService and FeatureLayer with editting turned on.  I am kind of stumped why this code doesn't work.  I thought it should work and the minimal code behind examples I have found are the same...

Any ideas why I am getting this error?

Cheers!
Brady
0 Kudos
JenniferNery
Esri Regular Contributor
It's hard to tell where it could have failed but the error comes from the service. What you can do is run Fiddler with your SL app. It might be able to tell you which webrequest failed and what parameters where used.
0 Kudos
BradyHustad
Emerging Contributor
It was in the behind.  The problem was two fold (if you can tell where I don't spend much time.. the server side!), so after much work with Esri Support...

[INDENT]1. Any layer you are editting must be registered as versioned.  This wasn't the one giving the error, I just found this out in my searches and realized I hadn't done that.
2.  The [ServerName]\ArcGISSoc account must have CRUD privileges on the table you are trying to edit.  That was the one that responded with this generic error.
[/INDENT]

Hope this helps some other person who isn't the master of the server he/she is writing code for.

Best Regards!

Brady
0 Kudos