Is it possible to set ContentType for WCF WebGet method?

I am working with the WCF restful / http method, which returns an image data stream. I want to make sure 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 an application / octet stream. Is there a way to change the type of content?

+3
source share
1 answer

Sorry, I just remembered that I did this before:

WebOperationContext.Current.OutgoingResponse.ContentType = "text/html"; // or anything
+8
source

All Articles