Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';通过web浏览器从WCF服务主机加载时无法获取文件大小_C#_Wcf_Webhttpbinding_Wcf Streaming - Fatal编程技术网

C# Can';通过web浏览器从WCF服务主机加载时无法获取文件大小

C# Can';通过web浏览器从WCF服务主机加载时无法获取文件大小,c#,wcf,webhttpbinding,wcf-streaming,C#,Wcf,Webhttpbinding,Wcf Streaming,我有一些带有流式webHttpBinding的测试WCF服务,它允许通过web浏览器下载文件。问题是浏览器不显示文件大小和下载进度。 这是服务合同: [服务合同] 公共接口IDataTransferService { [WebGet(UriTemplate=“下载?文件={fileName}”)] Stream GetDownloadStream(字符串文件名); } 这是服务实现: 公共密封类DataTransferService:IDataTransferService { 公共流GetD

我有一些带有流式webHttpBinding的测试WCF服务,它允许通过web浏览器下载文件。问题是浏览器不显示文件大小和下载进度。 这是服务合同:

[服务合同]
公共接口IDataTransferService
{
[WebGet(UriTemplate=“下载?文件={fileName}”)]
Stream GetDownloadStream(字符串文件名);
}
这是服务实现:

公共密封类DataTransferService:IDataTransferService
{
公共流GetDownloadStream(字符串文件名)
{
var context=WebOperationContext.Current;
var stream=File.OpenRead(文件名);
WebOperationContext.Current.OutgoingResponse.Headers[“内容处置”]=$“附件;文件名={Path.GetFileName(文件名)}”;
WebOperationContext.Current.OutgoingResponse.ContentType=“应用程序/八位字节流”;
WebOperationContext.Current.OutgoingResponse.Headers[“Content Length”]=stream.Length.ToString();
回流;
}
}
这是服务配置:



文件名显示正确,但缺少有关文件大小的信息。

尝试将transferMode更改为StreamdResponse

<binding name="streamedWeb" transferMode="StreamedResponse" sendTimeout="00:15:00" />

不,没有帮助。