3

正如主题所说,我从 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"%>
4

1 回答 1

3

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

于 2012-10-09T20:30:30.820 回答