Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an Silverlight application from which I'm trying to create new features to ArcGIS server. Every time I get error

{\"error\":{\"code\":400,\"message\":\"Unable to complete operation.\",\"details\":[\"Invalid parameters\"]}}

My request code is like this:

System.Net.WebClient client = new System.Net.WebClient(); client.Headers["Content-type"] = "application/x-www-form-urlencoded"; client.Encoding = System.Text.Encoding.UTF8; client.UploadStringCompleted += client_UploadStringCompleted;

client.UploadStringAsync(new Uri("http://.../FeatureServer/0/addFeatures?f=json&features"), "POST", JSONString);

If I copy the JSONString variable to a text editor, replace every escaped double quote mark (\") with double quote mark (") and use the ArcGIS servers /FeatureServer/0/addFeatures form, I am able to store the same features in that form to a featurelayer. That makes me thinking that the JSON data is well formed and valid for the featurelayer I'm using.

What could make the request response an error every time when called ArcGIS server from Silverlight application?

SOLVED:

I followed the instructions below and found a solution. First, the endpoint URL is like /.../FeatureServer/0/addFeatures, not like /.../FeatureServer/0/addFeatures?f=json?features

features=[{"geometry":{"x":0,"y":0}, "attributes":{"Id":"018-00","SV":"","Num":"4 A"}}]&f=json

Found the solution from here and by comparing the POST methods made from my application and the web form with Fiddler

share|improve this question
    
Any reason for constructing the request manually and not using FeatureLayer (help.arcgis.com/en/webapi/silverlight/help/index.html#//…) from the ESRI Silverlight API? –  Petr Krebs Oct 2 '12 at 16:25
    
Can we see the exact POST body? The url-encoded form will almost certainly not be identical to what you enter on the ArcGIS Server REST API page. –  Petr Krebs Oct 2 '12 at 16:27
    
For the first question: not really. I'll read the documentation again and see if I can use it. For the second question: I'll be check the POST body when I get back to it and see if I can provide some additional information from it. –  Olli W Oct 2 '12 at 16:55
2  
Your POST request will need to include parameters as described in the documentation, that is f and features. These parameters will need to be in the proper url-encoded format, which is not the same as what you enter in the REST page form. In any case, I suggest you try the FeatureLayer class. You do not need to add it to the map as most samples suggest. You can then either keep on using it, or capture with Fiddler what the correct request sent by the FeatureLayer looks like. –  Petr Krebs Oct 2 '12 at 17:12
    
Ok, thanks for your answers. One question: what would be the right way to add features to featureclass from Silverlight? I'm speaking of thousands of rows read from a csv file and saved to featureclass, without any direct user input besides the file. –  Olli W Oct 2 '12 at 17:51
show 1 more comment

2 Answers 2

up vote 1 down vote accepted

This is what a POST request to applyEdits looks like:

In the headers:

Content-type:application/x-www-form-urlencoded

POST body:

adds=%5b%7b%22geometry%22%3a%7b%22spatialReference%22%3a%7b%22wkid%22%3a102067%7d%2c%22paths%22%3a%5b%5b%5b-756462.345679012%2c-1044562.96296296%5d%2c%5b-756096.913580247%2c-1043695.0617284%5d%5d%5d%7d%2c%22attributes%22%3a%7b%7d%7d%5d&f=json&

which is the url-encoded form for these parameters:

adds=[{"geometry":{"spatialReference":{"wkid":102067},"paths":[[[-756462.345679012,-1044562.96296296],[-756096.913580247,-1043695.0617284]]]},"attributes":{}}]
f=json

I know you call addFeatures instead of applyEdits, but the principle is exactly the same.

Now, my guess is that your POST body is not url-encoded and is partial only, something like this perhaps:

adds=[{"geometry":{"spatialReference":{"wkid":102067},"paths":[[[-756462.345679012,-1044562.96296296],[-756096.913580247,-1043695.0617284]]]},"attributes":{}}]
share|improve this answer
    
For sure I was missing the "f=json" part of the post body since it was included in the url. –  Olli W Oct 2 '12 at 18:04
add comment

Use Fiddler to capture the request that works and the request that doesn't work, then compare them.

You can compare with Fiddler if you also have WinMerge - just select the two requests, right-click, and select Compare.

I suspect that you will find an encoding difference or an additional parameter in the working request. You can also use the WebForms inspector within Fiddler to quickly determine the form parameters that were submitted with the request (regardless of GET or POST)

My hunch is that your Invalid Parameters are a result of the additional ?f=json&features URI parameters on the URI argument for UploadStringAsync. POST parameters are part of the request body, so you probably have two f and two features parameters on your request.

share|improve this answer
    
With Fiddler I was able to see the request made from Silverlight app. It seemed ok with all JSON data as it was constructed and posted in the app. –  Olli W Oct 2 '12 at 16:56
    
Did you compare the Silverlight-made request with the form request? –  mwalker Oct 2 '12 at 17:01
    
Not yet. I'll have a look on it –  Olli W Oct 2 '12 at 17:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.