As Means said in his comment, the best option is to receive and return an array of bytes into your web service.
You can upload the file as bytearray using a method like this:
public byte[] FileToByteArray(string _FileName) { byte[] _Buffer = null; try { System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream); long _TotalBytes = new System.IO.FileInfo(_FileName).Length; _Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes); _FileStream.Close(); _FileStream.Dispose(); _BinaryReader.Close(); } catch (Exception _Exception) { Console.WriteLine("Exception caught in process: {0}", _Exception.ToString()); } return _Buffer; }
In addition, if you have deployed webservice as a WCF service, you may need to configure some settings to increase the amount of information you can send and the timeout. This is a sample binding configuration that allows this. (Only sample, may not meet your needs)
<binding name="WebServiceBinding" closeTimeout="00:02:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:02:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding>
source share