大家好, 我需要使用WCF服务使用流发送文件.尝试获取流的长度时出现错误. 在通过流的服务中,我发现流属性(例如流长度等)不允许. 我收到以下消息不支持指定的方法,SystemNotSupportedException".我传递给服务的流是转换为行Stream的FileStream,因为我需要读取文件,并且WCF仅接受行流. 有人可以找到解决方案吗? 谢谢.
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.
推荐答案我要做的是将文件的内容读入数组并将其发送给客户端.在这种情况下,您可能需要包括文件类型,更好的是,您可以为其创建包装器 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 [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
更多推荐
C#WCF通过流发送文件
发布评论