【发布时间】:2018-10-24 21:19:21
【问题描述】:
我有一个返回文件的 WCF webService 方法:
在 IMainService 中:
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/PerformScan")]
Stream PerformScan();
在 MainService.cs 中:
public Stream PerformScan()
{
MemoryStream SomeStream = new MemoryStream();
// Filling this memory stream using some processes on the data
WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-disposition", "inline; filename=Scan.Tiff");
return SomeStream;
}
这是我的 App.Config:
<system.serviceModel>
<services>
<service name="ShamsScanner.WCF.ScanService" behaviorConfiguration="mexBehavior">
<endpoint address="" binding="webHttpBinding" contract="ShamsScanner.WCF.IScanService" behaviorConfiguration="web"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:1369"/>
<add baseAddress="net.tcp://localhost:1369"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
当我在浏览器中调用此函数时。它不会返回任何内容。通过使用下载管理器,我会看到这个方法会不断被触发并且......什么都没有。
我已经将这个 MemoryStream 写在一个文件上,我发现它不是空的。
我应该怎么做才能返回文件?
【问题讨论】:
标签: c# web-services wcf stream