繁体   English   中英

Asp.net Web服务返回的docx文件

[英]Asp.net Webservice returning docx file

我有一些xml数据。 我已经制作了一个基于asp.net soap的Web服务,该服务将xml作为字节缓冲区,将xsl转换应用于它,并将其转换为docx文件。 但是,当我使用响应对象返回docx文件时,我得到一个错误,即客户端发现了application / vnd-word类型的响应,但它期望text / xml。

服务片段在xsl转换后推送文档文件

Context.Response.Clear();

Context.Response.ClearHeaders();

Context.Response.ContentType =“ application / vnd.openxmlformats- officedocument.wordprocessingml.document”;

Context.Response.AddHeader(“ Content-Disposition”,“ attachment; filename =” +“ test.docx”); Context.Response.Flush();

Context.Response.End();

这是通过网络服务呼叫吗? 如果您通过Web服务代理客户端进行调用,则它期望SOAP响应而不是二进制流。 您将需要对调用者可以理解的SOAP兼容响应进行建模。

设置content-type和content-disposition可让浏览器执行“正确的”操作(即打开文件保存对话框),但是自定义客户端(httpwebclient,Web服务代理等)没有内置的行为,因此您将需要添加所有丢失的内容。

您实际上在哪里写数据?

哦,试试看...(如果您的.docx是格式正确的Office openxml文件)

    Response.Clear();
    Response.ContentType = "application/msword";
    Response.AppendHeader("Content-Type", "application/msword");
    Response.AppendHeader("Content-disposition", String.Format("attachment; filename={0}", FileName));
    Response.BinaryWrite(DataBytes);
    Response.End();

    Response.Flush();
Context.Response.Clear();
Context.Response.ContentType = "application/msword"; 
Context.Response.AddHeader("Content-Type", "application/msword"); 
Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + "test.docx"); 
Context.Response.End();
Context.Response.Flush();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM