WCF分块/流 [英] WCF Chunking / Streaming

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

问题描述

我正在使用WCF,并希望将大文件从客户端上传到服务器。我已经调查并决定采用 http://msdn.microsoft .com / en-us / library / aa717050.aspx

I'm using WCF and want to upload a large file from the client to the server. I have investigated and decided to follow the chunking approach outlined at http://msdn.microsoft.com/en-us/library/aa717050.aspx

但是,这种方法(就像流式传输一样)将合同限制在有限的方法签署上:

However, this approach (just like streaming) restricts the contract to limited method signitures:

[OperationContract(IsOneWay=true)]
[ChunkingBehavior(ChunkingAppliesTo.InMessage)]
void UploadStream(Stream stream);

该示例使用了一个相当方便的示例,即从固定路径上载文件并将其保存到固定路径服务器上的路径。因此,我的问题是如何传递其他参数来指定文件名,文件路径等内容。

The sample uses the rather convenient example of uploading a file from a fixed path and saving it to a fixed path on the server. Therefore, my question is how do I pass additional parameters to specify things like filename, filepath etc.

例如。我想要类似的东西:

eg. I would like something like:

[OperationContract(IsOneWay=true)]
[ChunkingBehavior(ChunkingAppliesTo.InMessage)]
void UploadStream(Stream stream, String filePath);

在此先感谢
Mark。

Thanks in advance, Mark.

推荐答案

本文解释了如何使用MessageHeader属性强制事物在标头中传递,因此不算作参数。因此,与其传递流和其他元数据,不如创建一个具有MessageContract属性的类,并将所有元数据标记为MessageHeader。然后,将流标记为MessageBodyMember(文章错误地将其称为 MessageBody)。让您的UploadStream方法使用一个参数,该参数的类型应为您刚创建的MessageContract类的类型。我已经成功完成了此操作,但还没有与分块配合进行。祝你好运。

This article explains how to use the MessageHeader attribute to force things to be passed in the header, and therefore not count as a parameter. So, instead of passing a stream and other meta data, create a class that has the attribute MessageContract and mark all of the meta data as a MessageHeader. Then, mark the stream as a MessageBodyMember (which the article incorrect calls "MessageBody"). Have your UploadStream method take a single parameter whose type is that of the MessageContract class you've just created. I've done this successfully, but I haven't done it in tandem with chunking. Good luck.

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

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