如何设置从WCF返回的zip文件的名称

时间:2016-05-23 13:16:38

标签: vb.net wcf zip

我有一个用vb.net编写的WCF,我想从中返回一个zip文件。现在我可以使用它,但我无法弄清楚如何设置文件应保存为的建议名称(它默认为没有扩展名的操作名称)。当我保存文件然后用.zip扩展名重命名时,它就是我期望的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上设置一些内容,但看起来没什么。

1 个答案:

答案 0 :(得分:0)

这解决了问题:

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

应该相当明显,但我见过的所有示例都使用了WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream"设置