Question

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!!!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top