wcf - 是否可以为 WCF WebGet 方法设置 ContentType?

标签 wcf image http rest content-type

我正在使用返回图像数据流的 WCF restful/http 方法。我想确保内容类型被标记为“image/png”。该方法定义为:

[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;
    }
}

在 Firefox 中,内容类型似乎被标记为应用程序/八位字节流。有没有办法更改内容类型?

最佳答案

抱歉,我只记得我以前做过:

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

关于wcf - 是否可以为 WCF WebGet 方法设置 ContentType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5239790/

相关文章:

wcf - 如果我在AddObject上添加数据,如何返回ID?

wcf - 在 WCF 应用程序中设置 MSMQ 以确保可靠的邮件传递

jquery - WCF 正在更改从 jQuery .ajax 调用返回的 JSON 格式的日期时间

java - 如何在 TextView Android 上使用带有文本的图像(设备的存储图像)?

ruby-on-rails - 将相同的表单提交给不同的操作

performance - HTTP 请求与文件大小?

wcf - 没有从客户端计算机上的 Silverlight 发送 WCF 请求

css - Bootstrap 4 网格 "cube"

android - 获取 Android 上的照片库列表

javascript - f {$$状态 : {…}} in request instead of data