views:

933

answers:

4

I'd like this to be possible!

Can you write a web service (using C# and an asmx) that returns a ZIP file?

If so, can you give a simple example?

Thanks

+1  A: 

Sure thing,

No matter if it's a ZIP, DOC, PDF. We call that MTOM in the SOAP world

see this example yourself

balexandre
+2  A: 

This article shows how to return a file from webservice: http://articles.techrepublic.com.com/5100-10878_11-5805105.html.

empi
+1  A: 

I'm not sure you can use MTOM with vanilla .NET asmx services ( see here) . I know it's possible if using WCF though.

As a (poor) alternative, you could write a web method that returns the zipped data as a base64-encoded string (which would be probably quite long depending on the size of the file, so useful for small datasets only). Then you decode the string in the client to get the original data.

axel_c
For sending the base64 encoding back to the caller, should the InsertLineBreaks option of Base64FormattingOptions be used?
Tony Peterson
I think you can get away with just Convert.ToBase64String (byte[] data). See http://msdn.microsoft.com/en-us/library/system.convert.tobase64string.aspx for details.
axel_c
A: 

Thanks empi, I've got it all working. Marvellous...

SAL