geddylee74

SOE REST Web Service - How to return different MIME content types?

Discussion created by geddylee74 on Jul 9, 2010
Latest reply on Aug 18, 2011 by mcmpartner
Folks,

I posted this in the ArcObjects forum, but thought I'd see if anyone here might have an idea, too.

I've been messing around with the new types in ESRI.ArcGIS.SOESupport, starting at 10.0 Prerelease.  I've successfully built two little server object extensions that each expose a REST resource and REST operation.

My first SOE, which encapsulates some spatial and attribute query business logic and returns results as JSON, works fine when upgraded to 10.0 Release.  However, my other SOE, which does not return JSON, but instead a PNG image, doesn't work as expected.

The latter's REST operation functionality is generally (for the purposes of this question) encapsulated in a method whose signature conforms to the ESRI.ArcGIS.SOESupport.OperationHandler delegate.  As such, I'm able to simply return my PNG image as an array of bytes.  Back at 10.0 Prerelease, this worked splendidly.  I was able to do some heavy processing on the server, dynamically create a PNG, and return it back to the client.

After upgrading to 10.0 Release, and making the requisite changes to my REST operation's method signature (by adding an additional parameter, requestProperties), my SOE no longer returns a PNG image that clients can use; instead, it returns the PNG's byte array representation as text.

I've spent some time today looking into the cause of this, and it seems like this is the case:

1) At 10.0 Prerelease, my SOE's HTTP response contained no content type.
2) At 10.0 Release, the response contains this content type: "text/plain;charset=utf-8"

This seems to explain why I'm not seeing an honest-to-God image, but just a text representation of the bytes that make up the image.

Upon discovering this, I hit the documentation, trying to see if there was a way I could coax the SOE into specifying a different content type within the response.  The documentation on resources.arcgis.com didn't appear to say much (in fact, the ESRI.ArcGIS.SOESupport namespace doesn't even appear to exist in the API reference).  For the heck of it, I started poking around in VS 2010's Object Browser.

To my surprise, I noticed a new class - RestResponseProperties.  Looking at its documentation in the object browser, this seemed to be something useful, and might just give me what I need.  However, I'm not actually able to get it to work.  When I try something like this...


private byte[] MyRESTOperation(NameValueCollection boundVariables,
                                       JsonObject operationInput,
                                       string outputFormat,
                                       string requestProperties,
                                   out string responseProperties)
{

// Create the PNG image, and get it as an array of bytes.
byte[] pngAsBytes = myImageGeneratorClass.Generate();

// Then attempt to specify the HTTP response's 
// content type.  Let it be a PNG image (and not something else, like 
// plain text).
RestResponseProperties props = new RestResponseProperties();
props.ContentType = "image/png";
responseProperties = props.ToString();           

// Return the bytes.
return pngAsBytes; 

}


...I get the following response (in Firefox, fwiw)

{"error":{"code":500,"message":"An unexpected error occurred processing the request.","details":[]}}


which, unfortunately, doesn't give me a lot of love.

Does anyone know what the issue might be?  Are there only certain content types that I can use for RestResponseProperties.ContentType?  Or, are there certain values for these four parameters of an OperationHandler

operationInput: A JsonObject instance with the input for the operation.
outputFormat: The requested output format, for example "json".
requestProperties: Well-known properties of the request.
responseProperties: Well-known properties for the response.


that I need to set, or check for?  Perhaps an output format other than "json"?

Thanks!
Brooks

Outcomes