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; }
{"error":{"code":500,"message":"An unexpected error occurred processing the request.","details":[]}}
responseProperties[0] = @"{"Content-Type" : "image/png"}"
responseProperties = @"{"Content-Type": "..your mime type..", <...other HTTP headers...>}";
responseProperties = "{\"Content-Type\" : \"image/png\"}";
Content-Type: image/png; charset=utf-8
�?�PNG\r\n \x01A\n \x000\x000\x000\rIHDR\x000\x000\x002�?�\x000\x000\x001\x008\x006\x000\x000\x000>ó�?%\x000\x000\x000\x001sRGB\x000®�?\x01Cé\x000\x000\x000\x004gAMA\x000\x000±\x00Büa\x005\x000\x000\x000\tpHYs\x000\x000\x00E�?\x000\x000\x00E�?\x001�?o¨d\x000\x000ÿ¥IDATx^ìý�?ÏmͶæ\x007íýs�?�sï9ç\x016\t\x006C�??JS\n \x019�?TB \x004\x002\x004�?)�?�?�?�?�?\x015\x017�?]·Ý>�?;îd�?r�?ìXnZîXr�?�??;\x016B)ã\x004D�?��?�·ð-ò\x014{3ŸñŽ'ö3Ÿ5FD�?µ�?wïý}gméÝk�?�?�?1cFù�?�Ï�?�?ùþã�?ÿ�?wŸþ½Ï�?î\x017�?³0�?��?2®ŸþôÝû_üâÝ;üâ\x006~ü³Ÿ}r�?�?�?\x011�?�ÿèÏsõ�??g�?�ëª0êþá�? »w�?|£W½{\x0077M�?qþ\x01EnL+~�?í|õùìû�?÷ñ{�?ûä�?�s�?�?íW~åÝG�?\x01Fç8�?Ÿú�?ýWõ�?ÿ\x007?x¹\x01E¿�?�\x01BŽù\x007g=p�?��?��?��?�ã©é�?\x01D�?Ÿ~\x01EFÏ5�?�?9»^ãÐç©ŽÝçú;;v?\x016\x01Có2�?�?¿:Ÿ�?�åw´ÁQ/\x00Bÿ�?��?ìV÷^w5ù\x00CÏû*ò�?�?�?�ðŸ;*Ý 3>šŽG¯¿7ï?çu«òí�?rïu]\x01B,�?��?"#^µÝ~�?L�?ë�?�\x003o�??\x003ïÁç\x01F�?�?\x015�?¼#�?�]�?�?�?�û1ý�?¯�?\x01E\x00F¿\n ZÝ1"ª*°�? �?\x01A\x000MÁ�??ÿùzðñ°8÷øx\x003�?F'�?0zŽô9\þú¯\n
�PNG\r\n \x01A\n \x000\x000\x000\rIHDR\x000\x000\x002�\x000\x000\x001�\x008\x006\x000\x000\x000>��%\x000\x000\x000\tpHYs\x000\x000\x00E�\x000\x000\x00E�\x001�o�d\x000\x000��IDATx^��\x00B�u�Z�\x007�ͩZ\x00FKDDJ�V�Gj�V=R���\x014\x00F����9�� �" *nN\x00B�����@j��AC\x008�\x015kCH�j�\x00E�����\r��\x010��?�?5D�!�\x0105;��U�|�o��7�^�u�1�|�������?9ï ¿½ï¿½ï¿½ï¿½c��7����o����u/���M���%��u���v����^x�?¿ï¿½ï¿½/��%/P�������?s\x01Fï¿½ï¿½ï¿ ½ï¿½ï¿½ï¿½\x017�my\w�����_x�C>$\x01F��\x00B�?�??�a��&n�r���?���\x00F��\x017n>�C_������>��_�������?o
My guess is that the image bytes are getting re-encoded to UTF-8. So my question is, how are you generating the image? Can you show the code snippet that you are using?
// Create a BitmapSource instance, using the "pixels" array as the // source of the image. BitmapSource bitmapSource = BitmapSource.Create( width, height, 96, 96, PixelFormats.Pbgra32, null, pixels, (width * PixelFormats.Pbgra32.BitsPerPixel + 7) / 8); // Create a PngBitmapEncoder, which we'll use to actually create the // PNG image. PngBitmapEncoder encoder = new PngBitmapEncoder(); // Add a single bitmap frame to the encoder. The BitmapFrame represents // the image. encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); // Then, create a MemoryStream. Since we're going to return the PNG // as an array of bytes, we need to convert the image contents to // a byte array - and the MemoryStream serves as an intermediary // vehicle to perform this task. MemoryStream memStream = new MemoryStream(); // Tell the PngBitmapEncoder to save its contents to the memory // stream. (NOTE: You could use other streams, such as FileStream, // to save the contents to a different "media" if you wish.) encoder.Save(memStream); // Get an array of bytes from the MemoryStream, and return them. byte[] bytes = memStream.ToArray(); return bytes;
RestOperation png = new RestOperation("png", null, new string[] { "png" }, PngHandler); soeResource.operations.Add(png);
private byte[] PngHandler(System.Collections.Specialized.NameValueCollection boundVariables, ESRI.ArcGIS.SOESupport.JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = "{\"Content-Type\" : \"image/png\"}"; System.IO.FileStream fs = new System.IO.FileStream("c:\\temp\\8540.png", System.IO.FileMode.Open); System.IO.BinaryReader br = new System.IO.BinaryReader(fs); System.IO.MemoryStream ms = new System.IO.MemoryStream(); const int count = 1024; while(true) { byte[] buf = br.ReadBytes(count); ms.Write(buf, 0, buf.Length); if (buf.Length < count) break; } br.Close(); fs.Close(); fs.Dispose(); return ms.ToArray(); }
HTTP/1.1 200 OK Content-Type: image/png ETag: -969848622 Server: Microsoft-IIS/7.5 X-Powered-By: ASP.NET Date: Thu, 22 Jul 2010 18:16:45 GMT Content-Length: 2561