如何将流与返回大型数据集的 WCF 服务结合使用?
我对 WCF 相当陌生,我正在尝试弄清楚流式传输的工作原理。我基本上有一个 Web 服务,应该从数据库返回一些信息。返回的数据可能非常大。我想知道是否有人可以指出一个很好的例子来说明这是如何完成的。如果我理解正确的话,我的 Web 服务方法应该返回一个流对象。但是我如何实际将数据传递到流呢?这只是序列化每个对象并将其写入流的问题吗?如果是这样,序列化到底是如何完成的?再次,如果有一个简单的例子,我们将非常感激。
I'm fairly new to WCF and I'm trying to figure out how streaming works.I basically have a web service that is supposed to return some information from a db.The data returned is potentially very large.I was wondering if anyone could point out a good example of how is this done.If I'm understanding things correctly, my web service method should be returning a stream object.But how do I actually pass data to the stream? Is it just a matter of serializing each object and writing it to the stream? If so, how exactly would the serializaition be done? Once again, a simple example would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需将 Binding 的 TransferMode 属性设置为 Streamed像您一样重视并使用您的 WCF 服务。 WCF 基础结构将自动完成所有工作。
这是一个更有用的链接:
流式消息传输
You should just set the Binding's TransferMode property to the Streamed value and work with your WCF services as you would do. The WCF infrastructure will do all the job automatically.
Here is one more useful link:
Streaming Message Transfer
实际上,我会重新审视该架构,因为从任何服务(WCF、ASMX 等)返回大型结果集都是一种架构味道。
从服务返回大型结果集的可接受理由很少。更多/更好的过滤和实现页面的组合是解决方案。如果您只是在数据库上放置一个简单的服务胶合板,请考虑 WCF 数据服务,因为过滤和分页直接内置于框架中。否则,请查看 WCF 数据服务以了解它们正在做什么并在您的服务中进行模仿。
Actually, I'd revist the architecture, as returning large resultsets from any service (WCF, ASMX, etc) is an architecture smell.
There are very few acceptable reasons to return large resultsets from a service. A combination of more/better filtering and implementing pagine are the solution. If you are just putting a simple service veneer over your database, look into WCF Data Services, as filtering and paging are built right into the framework. Otherwise, look into WCF Data Services to see what they are doing and mimic in your service.