Is it possible to set ContentType for a WCF WebGet method?
- by James Cadd
I'm working with a WCF restful/http method that returns a stream of image data. I want to make sure that the content type is marked as "image/png". The method is defined as:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class TileImageService
{
[WebGet(UriTemplate = "{id}")]
public Stream GetTileImage(string id)
{
Bitmap bmp = new Bitmap(173, 173);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.Blue);
g.DrawString(DateTime.Now.ToLongTimeString(), new Font("Chiller", 20), Brushes.White, new PointF(10, 10));
g.Flush();
MemoryStream ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
return ms;
}
}
In Firefox it looks like the content type is marked as application/octet stream. Is there a way to change the content type?