The best and most optimized way to return a filestream from a .NET WCF SOAP service

netsoapwcf

To give some background, i have a WCF SOAP service in .NET that needs to return pdf files. This service will be used by multiple application, many times in a day. The size of the files returned varies from 10KB to 10MB. Also, there is no shared location where the file can be kept and the path can be returned. It can be done using byte[], but that will increase the load on service, which I want to avoid. Any suggestions are welcome.

Application is hosted as a windows service. It is being used mostly by Java Clients. When I am trying to directly return the file stream, at client side the return type does not get mapped to a proper class and returns a null object in an automatically generated empty class. Only in the case when I returned byte[], it was able to read the file.

Best Answer

Message Transmission Optimization Mechanism (MTOM) is a mechanism for transmitting large binary attachments with SOAP messages as raw bytes, allowing for smaller messages.

please refer : http://msdn.microsoft.com/en-us/library/aa395209.aspx for more details.