c# - 无法从 WCF Rest 服务返回图像

标签 c# wcf image rest

如主题所述,我在从我的 Wcf 休息服务接收图像时遇到问题。端点似乎没问题,但我只返回空数据。

网络配置:

  <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
    <endpoint address ="" binding="webHttpBinding"                     contract="RestService.IRestServiceImpl" behaviorConfiguration="web"/>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>

SVC:

        [OperationContract]
    [WebGet(UriTemplate = "GetImage", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
    Stream GetImage();

    public Stream GetImage()
    {
        var ms = new MemoryStream();
        Resource1.batman.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        WebOperationContext.Current.OutgoingResponse.ContentType = "image/png";
        return ms;
    }

标记:

<%@ ServiceHost Language="C#" Debug="true" Service="RestService.RestServiceImpl" CodeBehind="RestServiceImpl.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>

最佳答案

尝试在返回前将内存流的 Position 设置回 0。

关于c# - 无法从 WCF Rest 服务返回图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12781173/

相关文章:

c# - 对 rtfbox 和文本文件中的字符串数组进行排序/排序

c# - 使用 C# 泛型从方法创建泛型对象(不是 "new")

c# - 从 TCP 的角度来看,WCF webHTTPbinding 是什么?

css - 替代背景大小 : cover for img tags?

c# - ASP.NET Identity 外部登录 - 如何获取用于 API 调用的 Google token ?

jquery - 使用 NSError 处理 WCF REST 服务和 iOS 错误

linux - MONO WCF 自托管服务对在使用 net.tcp 时由对等方重置连接

java - 将 ImageIcon 设置为全屏

php - 在 PHP 中创建图像以显示吉他和弦

C# 文本框字符串分隔