[GIS] ‘invalid parameters’ on ArcGIS rest API used from Silverlight

arcgis-rest-apiarcgis-serverarcgis-silverlight-apifeature-servicejson

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

Best Answer

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":{}}]
Related Question