开发者

Asp.net Webservice returning docx file

I have some xml data. I've made an asp.net soap based webservice that takes the xml as a byte buffer applies xsl transformation to it and converts it to a docx file. But when i return the docx file using the response object i get an error that client found response of type application/vnd-word but it was expecting text/xml.

Service Snippet to push document file after xsl transformation

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();


Is this via a webservice call? If you are calling via a webservice proxy client, then it is expecting a SOAP response and not a binary stream. You will need to model a SOAP-compatible response which the caller can understand.

Setting the content-type and content-disposition enables a browser to do the "right" thing (ie open the file-save dialog) but custom clients (httpwebclient, web service proxy, etc) don't have those behaviors built-in so you will need to add whatever is missing.


Where are you actually writing the data?

oh and try this... (if your .docx is a well formed office openxml file)

    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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜