views:

351

answers:

1

I'm trying to serve up Excel documents that I have stored in a database via a WCF RSS feed (the user clicks a link in the feed and it sends down a specific Excel document).

The Excel files aren't sitting in a directory any where (in which case I could just give each user a static URL).

So what I'd like to do is have a dynamically generated URL in the RSS feed (which would indicate the ID of the document). When the user clicks the URI it goes to a WCF webservice that deserializes the Excel document out of the database and sends it to the user (they'd get the standard Open/Save Excel document dialog).

Unfortunately I can't seem to get the web service to send a document that the client understands is an Excel document. I figure that I need to do something with the endpoint or some MIME setting in IIS or something else altogether, but I haven't figured out what that is.

Note, I'm using WCF hosted on IIS 7.0.

Much thanks in advance!!!

+1  A: 

You don't give too much specific information but it could be that you didn't set the MIME type. Not sure what you've already done but you can do what you want using the WCF Rest Programming Model.

The key points are to:

  • return a Stream on your interface
  • set the MIME type: WebOperationContext.Current.OutgoingResponse.ContentType = "application/vnd.ms-excel";
  • use the WebHttpBinding and WebHttpBehavior

MSDN has a full example that returns a JPEG which should do exactly what you want (except change the JPEG MIME type to an Excel MIME type as above).

Good luck.

Tuzo
Thank you Tuzo. This sounds like the info that I need. I have some other work that I need to do first, but I will get to thi over the next day or so and let you know how it goes. Again, thanks.
Kang Su
Tuzo this appears to have done the trick. I was returning a byte[] rather than a stream, and wasn't propertly setting the MIME type in WCF. Again, thanks for the help!
Kang Su