WCF文件流+ ASP.NET [英] WCF File Streaming + ASP.NET

查看:112
本文介绍了WCF文件流+ ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一次上传最多2 gb的文件数据,并将其保存到数据库中以进行WCF调用.我已经看到了许多关于文件流的实现,问题是我还有其他相关数据,这些数据需要与数据(流水箱中用户选择的几个项,字符串列表等)一起发送.但是流仅支持System.IO的单个参数,或者最大程度地传递了一些消息头,但是我有一个数据表,需要将其与文件数据一起传递给WCF,Cant似乎想出了如何在其中发送这两个数据一个电话.由于实现了类似

void UploadFile(System.IO.Stream someStream)不允许将任何其他参数从流中传递出去,在服务器上,我可以将流读取为byte [],但要将byte []插入数据库中,则需要附加来自用户的文件输入,其具有来自列表< string>的许多附加元数据值.长ID的元素.

需要变通,以便我既可以传递流又可以传递数据集,在其中我可以保存所有列表< string>. ,长值

消息合同不允许使用数据合同,而数据合同不能实现启用流的全部目的,任何想法都可以吗?

I need to upload upto 2 gb of file data in a single go and save it to the database making a WCF call. I have seen a lot of implementations on File Streaming, the problem is I have other related data which I need to send over with the data (couple of user selected items from drop boxes , list of strings etc) along with the streamed data. But streaming only supports single Parameter of System.IO or at max pass some message headers but I have a data table that I need to pass over to the WCF along with the file data, Cant seem to figure out how to send both the data in a single call. Since implementing something like

void UploadFile(System.IO.Stream someStream) doesn''t allow any additional parameters to be passed apart from the stream and at the server I can read the stream to byte[] but to insert the byte[] into database I need additional inputs for the file from the user which has many additional metadata values from list<string> elements to long ids.

Need a work around so that I can pass both the stream and preferably a dataset in which I can save all the list<string> , long values

Message contracts don''t allow Data contracts which beats the whole purpose of enabling streaming, any ideas anyone ?

推荐答案

将数据集序列化为JSON,将JSOn字符串一个字节数组,然后使用其他定界符将该字节字符串附加到文件字节数组的前面,以便可以在WCF端将其删除.

结果?单个IOStream在文件本身内部传递了附加信息.

WCF不在乎流的内容,您可以执行Stream>>.在将Stream转换回File之前,先在WCF服务器端进行byte []转换.


记住乡亲,1和0.这就是我们所要做的. 1和0.
Serialize your dataset into JSON, take the JSOn string to a byte array, and append that byte string to the front of your file byte array using additional delimiters so you can strip it out on the WCF side.

Result? Single IOStream passed with additional info inside the file itself.

WCF doesn''t care about the contents of the stream, and you can do a Stream >> byte[] conversion back on the WCF server-side prior to converting the Stream back to a File.


Remember folks, 1s and 0s. That''s all we deal with. 1s and 0s.


这篇关于WCF文件流+ ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆