Is it possible to set ContentType for a WCF WebGet method?
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 "ima开发者_运维问答ge/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?
Sorry I just remembered I had done it before:
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html"; // or anything
精彩评论