Proxy, POST, and Tokens

1649
9
Jump to solution
01-14-2014 10:56 AM
DavidLowther
New Contributor
I have configured the proxy.ashx with my URL and token and am successfully using it for GET requests (DynamicMapServiceLayer drawing and FeatureLayer.queryFeatures).

When I try an operation that requires POST, things do not go as well. I'm attempting to call FeatureLayer.applyEdits as follows:

         
ROWLayer.queryFeatures(q, function (featureSet) {                 if (featureSet.features.length == 1) {                     var thisFeature = featureSet.features[0];                     thisFeature.attributes.ContactName = 'Some Body';                     ROWLayer.applyEdits(null, [thisFeature], null);                 }             });


The proxy appends the token to the URL which (I guess?) makes the POST request invalid or incorrect. The response I receive is the JSON version of the FeatureLayer info page.

Can anyone tell me what I am doing wrong?

Thanks in advance,

Dave
0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor
My gut reaction to your code is that you are trying to apply edits to a map service feature layer. I don't think this is possible.

You need to use a feature service feature layer to apply edits.

If you go to REST and look at the Supported Operations, only the feature service feature layer will have the option of Apply Edits.

Does this help?

View solution in original post

0 Kudos
9 Replies
Noah-Sager
Esri Regular Contributor
Hi Dave,

Does the POST request work without the proxy?

I would suggest you watch the web traffic when you make GET and POST requests to see what parameters you are passing (make sure these are valid) and what the error message is.

-Noah
0 Kudos
DavidLowther
New Contributor
Noah,

Thanks for the quick response.

If I make the request without the proxy I receive a Login page in response (which makes sense, but tells me nothing about whether the request would be correct if it made it through). I am watching the requests and responses using Fiddler.

Dave
0 Kudos
Noah-Sager
Esri Regular Contributor
Do you see any error message in Fiddler with the POST request through the proxy? Or are you just getting unexpected results?
0 Kudos
DavidLowther
New Contributor
No error message, just unexpected results.
0 Kudos
Noah-Sager
Esri Regular Contributor
Hmm, hard to say. If you are able, feel free to post a sample app that exhibits this behavior.

Alternatively, have you looked through our editing samples for examples of a similar workflow?

Edit without editor widget sample
0 Kudos
DavidLowther
New Contributor
Noah,

There's not much to it. Here is the web page:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestSaveDelete.aspx.vb" Inherits="HilandWeb.TestSaveDelete" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test Save and Delete Functions</title>
    <script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
    
    <script src="http://js.arcgis.com/3.7/" type="text/javascript"></script>

    <script type="text/javascript">
        var ROWLayer;
        var q;

        require([
            "esri/config",
            "esri/layers/FeatureLayer",
            "esri/geometry",

            "esri/tasks/query",

            "dojo/domReady!"
        ], function (
            esriConfig,
            FeatureLayer,
            Geometry,

            Query
            ) {
            esriConfig.defaults.io.proxyUrl = "proxy.ashx";
            esriConfig.defaults.io.alwaysUseProxy = true;

            ROWLayer = new FeatureLayer("http://thegisserver/arcgis/rest/services/Hiland/ROW/MapServer/0",
            { outFields: ["*"] });


            q = new Query();
        });

        function update() {
            q.objectIds = [2395];

            ROWLayer.queryFeatures(q, function (featureSet) {
                if (featureSet.features.length == 1) {
                    var thisFeature = featureSet.features[0];
                    thisFeature.attributes.ContactName = 'Jake Lowther';
                    ROWLayer.applyEdits(null, [thisFeature], null);
                }
            });

        }
    </script>
    </head>
<body>
    <form id="form1" runat="server">
    <div>
    
<input type="button" onclick="javascript:update();" />
    </div>
    </form>
</body>
</html>


I'm using the proxy.ashx provided by ESRI. My config looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig mustMatch="false">
  <serverUrls>
    <serverUrl url="http://thegisserver/arcgis/rest/services/" 
               matchAll="true" token="FykBFF29p8_4Gt2nTw57Eh2G_yows8koT--8Z7Q__34cf6gQQDwGp1H59EZrBc1h "></serverUrl>
  </serverUrls>
</ProxyConfig>


When the page loads there is a successful call to the layer to establish the FeatureLayer (everything in the query string):

GET /arcgis/rest/services/Hiland/ROW/MapServer/0?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback&token=FykBFF29p8_4Gt2nTw57Eh2G_yows8koT--8Z7Q__34cf6gQQDwGp1H59EZrBc1h HTTP/1.1

When the button is clicked the first call (queryFeatures) is successful (everything in the query string):

GET /arcgis/rest/services/Hiland/ROW/MapServer/0/query?f=json&returnGeometry=true&spatialRel=esriSpatialRelIntersects&objectIds=2395&outFields=*&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback&token=FykBFF29p8_4Gt2nTw57Eh2G_yows8koT--8Z7Q__34cf6gQQDwGp1H59EZrBc1h HTTP/1.1

The the applyEdits call looks like this (token in the query string, f and updates in the body):

POST /arcgis/rest/services/Hiland/ROW/MapServer/0/applyEdits?token=FykBFF29p8_4Gt2nTw57Eh2G_yows8koT--8Z7Q__34cf6gQQDwGp1H59EZrBc1h HTTP/1.1

But the result of the applyEdits is shown below (clearly not an applyEdits result...):

[ATTACH=CONFIG]30505[/ATTACH]

I believe that if you attempted to applyEdits to any secured FeatureLayer via the proxy using a token you would see similar results.

Can you confirm?

Thanks again,

Dave
0 Kudos
Noah-Sager
Esri Regular Contributor
My gut reaction to your code is that you are trying to apply edits to a map service feature layer. I don't think this is possible.

You need to use a feature service feature layer to apply edits.

If you go to REST and look at the Supported Operations, only the feature service feature layer will have the option of Apply Edits.

Does this help?
0 Kudos
DavidLowther
New Contributor
Noah - the Apply Edits is not listed as a Supported Operation. I'll look into your suggestion and get back ASAP.

Thanks!

Dave
0 Kudos
DavidLowther
New Contributor
Noah,

Same operation on a FeatureLayer from a FeatureService works like a charm. Thanks for helping me get to the bottom of it!

Dave
0 Kudos