Using addFeatures?f=json&features POST JSON feature get "Invalid parameters" response

4355
1
06-14-2010 06:21 AM
WillBranch
New Contributor II
We are trying to add points to our own AGS V10 feature server using REST in C#. Using the HTML form I can submit the same JSON feature that I am POSTing in code and it is successful. 

I don't know what is wrong with my parameters since there are no published examples for this 😞 😞

Was hoping to have this working for a webex today at 2:00 eastern so I can get an OK to go forward on using Feature Services.

Thanks!

here is my code:
        public void AddNewFeature(string aJSONString)
        {
            string aUrl = string.Format("{0}/{1}", _url.AbsoluteUri, "addFeatures?f=json&features");
            Uri aUri = new Uri(aUrl);
            string aRespStr = "";

            using (WebClient client = new WebClient())
            {
                client.Headers["Content-type"] = "application/json";
                client.Encoding = Encoding.UTF8;
                aRespStr = client.UploadString(aUri, aJSONString);
                   //aRespStr = client.UploadString(aUri, HttpUtility.UrlEncode(aJSONString));
            }
        }


Here is the JSON feature I am posting:
[{"geometry":{"x":-9107536.44005102,"y":3321905.0880102},"attributes":{"HOUSE_NO":"123456","ST_NAME":"WillTest","COMMENTS":"IslandHouse"}}]

Fiddler info re: request:
POST http://vmgsc/ArcGIS/rest/services/LeesburgFL_FeatureServiceTest/FeatureServer/0/addFeatures?f=json&f... HTTP/1.1
Content-Type: application/json
Host: vmgsc
Content-Length: 79
Expect: 100-continue

[{"geometry":{"x":403778.3,"y":1604409},"attributes":{"HOUSE_NO":"555666777"}}]

Fiddler info re: Response:
HTTP/1.1 200 OK
Content-Type: text/plain;charset=utf-8
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Mon, 14 Jun 2010 13:55:16 GMT
Content-Length: 98

{"error":{"code":400,"message":"Unable to complete  operation.","details":["Invalid parameters"]}}
0 Kudos
1 Reply
VasylMelnychuk
New Contributor
You are using invalid URL for this action. Parameters "f" and "features" need to be POST parameters.

Use URL:
http://vmgsc/ArcGIS/rest/services/LeesburgFL_FeatureServiceTest/FeatureServer/0/addFeatures

Your code must be similar to:

using (System.Net.WebClient client = new System.Net.WebClient())
{
    client.Headers["Content-type"] = "application/x-www-form-urlencoded";
    client.Encoding = System.Text.Encoding.UTF8;
    var collection = new System.Collections.Specialized.NameValueCollection();
    collection.Add("f","json");
    collection.Add("features", aJSONString);
    var response = client.UploadValues(aUri, "POST", collection);
    MemoryStream stream = new MemoryStream(response);
    StreamReader reader = new StreamReader(stream);
    aRespStr = reader.ReadToEnd();
}
0 Kudos