Hello.I tried to reproduce this situation from scratch. I downloaded 'SimpleRESTSOE' example from ESRI (here)and added simple 'png' method that reads a PNG file from disk and returns it as byte array.I added the following snippet to CreateRestSchema()RestOperation png = new RestOperation("png",
null,
new string[] { "png" },
PngHandler);
soeResource.operations.Add(png);
and the handler itself:
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();
}
requested: h ttp://localhost/ArcGIS/rest/services/Test/MapServer/exts/SimpleRESTSOE/png?f=pngAnd I got back valid PNG displayed in browser. HTTP response headers are here:
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
NOTE: There's no extra charset=utf-8 . I believe this extra encoding bit makes all the difference. Please verify that you do not add this encoding somewhere else in your code.Hope this helps.Sergey Malgin