problem with ResponseProperties.ResponseDataType in REST SOE

494
6
07-09-2010 07:26 AM
PrashantKhanal
New Contributor
So I really like the concept of supporting REST in SOE and I have been working on it since past couple of months.
Basically I am following the presentation - Extending AGS Services Using .NET to develop SOE that provides REST services. I was looking for an option where i can stream the image in the output response.
I used ResponseProperties.ResponseDataType = esriWebResponseDataType.esriWRDTFileToReturn in an operation and returned the file name from the operation. The ESRI server gives an error saying Could not find a part of the path. I tried many possible combinations. I thought giving an absolute path such as "c:\arcgisoutput\test.jpg" should work but doing so gives c:\ is not a virtual path. I think ESRI server use Response.TransmitFile to stream the file contents back to the client. Where does the ESRI server looks for the file. Shouldn't giving the absolute file path work?
0 Kudos
6 Replies
RahulRavikumar
New Contributor
You could generate the image into a file and return it as bytes, and specifying a MIME type as "image/..." as the Content-Type.

You could do:


  //Generate your image
  byte [] image = image.getBytes();
  responseProperties[0] = @"{"Content-Type" : "image/png" }"
  return bytes;
0 Kudos
PrashantKhanal
New Contributor
Thanks for the reply.
Returning image as bytes and changing the "Content-Type" header sounds a good approach. To my understanding, for every REST operation, the client must specify the output format as say f=json or f=html or f=pjson and I believe the SOE REST request handler only support these three formats for now.
So my concern is the requested output format can be either json/pjson/html even though my operation tries to send the image bytes with proper "Content-Type" header. Isn't it misleading?
Correct me if I am missing something in here?
0 Kudos
BrooksShannon
New Contributor
Thanks for the reply.
Returning image as bytes and changing the "Content-Type" header sounds a good approach. To my understanding, for every REST operation, the client must specify the output format as say f=json or f=html or f=pjson and I believe the SOE REST request handler only support these three formats for now.
So my concern is the requested output format can be either json/pjson/html even though my operation tries to send the image bytes with proper "Content-Type" header. Isn't it misleading?
Correct me if I am missing something in here?


Prashant,

While my SOE is generating PNG images on the fly, and returning them in the response (instead of writing them to disk, on the server, and returning a URL to them), you might find my thread of interest.

http://forums.arcgis.com/threads/7993-SOE-REST-Web-Service-How-to-return-different-MIME-content-type...

I haven't yet received a solution to my problem, but I thought that since we appear to be performing similar work, you might like to see what the solution to my issue is - assuming I'm able to find one. 🙂

Thanks,
Brooks
0 Kudos
PrashantKhanal
New Contributor
Hi Brooks,

I saw your post and i did work the way you described but haven't found solution yet 🙂 . Somehow i feel i am closer to the solution but haven't reached there yet. So i have been trying different tricks.

My question to you is what would be the requested output format to invoke your operation that returns the PNG image as bytes.

One way i found to work with images as per the
page 50 in http://proceedings.esri.com/library/...using_.net.pdf
I used the ResponseProperties.ResponseDataType = esriWebResponseDataType.esriWRDTFileToReturn;

This way the ESRI server tries to stream the file. The returned bytes for such operation should be the virtual path to the file name to my understanding. I am getting error in virtual path doing so. That does mean the ESRI server is looking for the file to stream in response.

Now the way you did, So you are able to get the PNG response but there is some error in PNG response right?

Can you send me the snippet of your operation that sends the PNG image and how did you create the operation. What were the supported ouptut formats?

Perhaps I can move forward with your help and we can figure out the solution.

Thanks,
Prashant Khanal
0 Kudos
PrashantKhanal
New Contributor
Problem Solved!!
The problem does not exist anymore in the released version.
0 Kudos
nicogis
MVP Frequent Contributor
You could generate the image into a file and return it as bytes, and specifying a MIME type as "image/..." as the Content-Type.

You could do:


  //Generate your image
  byte [] image = image.getBytes();
  responseProperties[0] = @"{"Content-Type" : "image/png" }"
  return bytes;


Raul: responseProperties is a string. it isn't a string[].
0 Kudos