Is it possible to set ContentType for a WCF WebGet method?
Posted
by
James Cadd
on Stack Overflow
See other posts from Stack Overflow
or by James Cadd
Published on 2011-03-08T23:50:10Z
Indexed on
2011/03/09
0:10 UTC
Read the original article
Hit count: 253
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?
© Stack Overflow or respective owner