I am able to find the reason for the above error. It looks like an ESRI bug to me.
One of the parameter that I pass to gp.Execute() method is a FeatureSet. This FeatureSet contain a polygon with empty geometry and few attributes. My output will add geometry to this FeatureSet.
When map's spatial reference is GCS, the GP tool works fine. But when the spatial reference is PCS, the FeatureSet requires some geometry for the polygon. I am not sure why it is so.
So I am adding few dummy rings to the polygon to get it working.
The line polygon.addRing ... below was added to fix the issue discussed above. I guess we can add any dummy ring values there.
If anybody can give a better reason why this is only required when the spatial reference is PCS, I appreciate it.
.....
......
var attr = {"id":1, "legalParams":legalParams };
var polygon = new esri.geometry.Polygon(map.spatialReference);
polygon.addRing([[-180,-90],[-180,90],[180,90],[180,-90],[-180,-90]]);//This line is added to fix the issue discussed above. This is not required for GCS
var graphic = new esri.Graphic(polygon, null, attr, null);
legalFeatureset = new esri.tasks.FeatureSet();
legalFeatureset.spatialReference = map.spatialReference;
.......
''''''
var features = [];
features.push(graphic);
legalFeatureset.features = features;
legalFeatureset.geometryType = "esriGeometryPolygon";
.......
'''''''
gp.execute(params, drawGeoprocessingResult, getError);
Async writes to the Job directory and those results are persisted until the Server cleans them up.
Sync sends the results back to the client.
With a GP Service you should return a file or data, not a directory (especially with Sync).
The framework is meant to return these outputs, it isn't meant to return a folder you can browse to. You'd have to expose output directories and then send back a basic string of that location.
In this case you may need to set your output to file and return it like:
arcpy.SetParameterAsText(#, os.path.join(arcpy.env.scratchFolder, "myfile.zip"))
Best Answer
You need a proxy page in mainly two conditions:
The application uses GET requests that exceed 2048 characters.
The JavaScript makes a HTTP (besides Images & Scripts) request to a server on a different domain, which does not support JSONP.
You are facing the first problem:
I would request you to look at the following page: Using the proxy page
This page will give you basic information about a proxy page, as well as how to set it up.
You do not need to explicitly make the request a POST request if you are using ArcGIS API classes. They automatically become a POST request whenever needed.
And you don't actually need a dojo.deferred(). If you have set up the handlers properly, it should work fine.