2016-05-23 37 views
0

我有一个写在vb.net的WCF,我想从中返回一个zip文件。现在我可以得到这个工作,但我不知道如何设置文件应该保存为的建议名称(默认为不带扩展名的操作名称)。当我保存文件,然后用.zip扩展名重命名时,它就是我期望的zip文件。如何设置从WCF返回的zip文件的名称

所以我想能够设置文件扩展名,我想我没有被文件名打扰。

这里是我的示例代码:

<WebGet(UriTemplate:="Export/", ResponseFormat:=WebMessageFormat.Xml, BodyStyle:=WebMessageBodyStyle.Bare)> 
Public Function ModelVersionExport() As System.IO.Stream 

    WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream" 

    'then I call my code that creates the io.stream of the zip file (that works fine) 

End Function 

我想也许我可以设置在OutGoingResponse的东西,但没有什么期待权。

+0

秀'创建ZIP file' – Claudius

+0

流的io.stream没有工作,我的问题是它保存的文件被称为“导出”,没有文件扩展名。 – sbarnby71

回答

0

此修复该问题:

WebOperationContext.Current.OutgoingResponse.ContentType = "application/zip" 

本来应该是相当明显的,但我看到的所有例子中使用的WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream"设置

相关问题