正如主题所说,我有一个问题是从我的Wcf休息服务接收图像。端点似乎没问题但我只能获得空数据。
的Web.config:
<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"%>
答案 0 :(得分:3)
尝试在返回前将内存流的位置设置回0。