views:

30

answers:

1

I already have a method in my webservice that returns a byte[] containing only the bytes of the file downloading. The invocation is something like:

http://www.mysite.com/myWebservice.asmx

with:

string fileId = "123"; bytes[] fileContent = myWebservice.Download(fileId);

What I wanted to do is be able to invoke this method or other (to be made) on a aspx webpage and be able to open a browser window containing the real content of the file.

i.e. Most files are TXT and PDF. (Assuming the client has the PDF plugin that alows him\her to view PDF's on the browser.)

A: 

If you want the browser to open a file automatically, your web server needs to return the proper MIME type for that file.

Most likely you'll need to set the context.Response.ContentType and call context.Response.AddHeader from your code.

Configuring the server to handle a specific MIME type is server specific; my company's server (http://www.neokernel.com) uses a text configuration file to define mime types. With IIS, you need to use the IIS management console.

There is a code snippet here that may be useful: http://stackoverflow.com/questions/952667/solved-how-to-output-a-simple-c-asp-net-generated-kml-file

Damien
That solution applies to Handlers (ashx) and not to webservices (asmx)...
gafda
Oops, apologies i didnt' read closely enough. http://msdn.microsoft.com/en-us/library/system.web.script.services.responseformat.aspx indicates that you are limited to JSON or XML responses from classical (asmx) web services, so you will probably need to do this as ashx.
Damien