Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I need to send a file using a stream using WCF services. I got an error when trying to get the length of the stream.
At the service when I pass the stream I found that the stream properties like stream length,etc are not allowing.

I got following message "Specified method is not supported, SystemNotSupportedException". The stream I passed to the service is a FileStream casted to row Stream since I need to read a file and WCF only accepts row Streams.

Can someone find a solution for this?

Thanks.
Posted

1 solution

what I would do is read the content of the file in to an array and send that to the client. in that case you would need to include the file type probably, better yet you can create a wrapper for it

C#
[Serializable]
       class Filewrapper
       {
           public byte[] FileContent { get; private set; }
           public string FileName { get; private set; }
           public Filewrapper()
           { }
           /// <summary>
           ///
           /// </summary>
           /// <param name="content"></param>
           /// <param name="name">only the file name not the full path</param>
           public Filewrapper(byte[] content, string name)
           {
               FileContent = content;
               FileName = name;
           }
       }

then your service would return something like this

string strpath="file path";
Filewrapper fl = new Filewrapper(File.ReadAllBytes(strpath),Path.GetFileName(strpath));


hope this helps
 
Share this answer
 
Comments
thanushkag 16-Aug-10 3:29am    
Hi Thanks for answering, I tried to send as a byte array, but the problem is it's not working when the file size is large. I need to send large files.

Thanks.
Vinayaka Krishna Shenoy 16-Aug-10 4:29am    
Hi,

If it says file is large,then you might have to tune the entries for maxreceivedmessage size, max arrayay langth and Buffer size.

Try to increase those values.

I hope this helps!.

Regards,
-Vinayak
Samuel Cherinet 16-Aug-10 22:57pm    
yap! there are a bunch of default setting for the channel in the config file. all you gotta do is increase those values and it should work for you. I have used WCF for a file server and had run into the same issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900