自定义流从MS-SQL读BLOBS - 我应该如何处理连接? [英] Custom streaming to read BLOBS from MS-SQL - How should I handle the connection?
问题描述
我有一个自定义流,我使用WCF从数据库的大型BLOB。它读取块中的数据。
I have a custom stream that I am using with WCF for large BLOBs from the database. It reads the data in chunks.
处理流的连接的最佳方法是什么?
What is the best way to handle the connection for the stream? Should I just open it at the construction or open/close it with each chuck read?
谢谢。
推荐答案
我会将整个blob加载到内存流,然后让WCF处理Streaming和Chunking。您可以在transportBindings中启用流式传输或使用MTOM进行查看。
I would load the entire blob into a memory stream then let WCF handle the Streaming and Chunking. You can enable streaming in the transportBindings, or look into using MTOM.
[ServiceContract]
public class ContentService
{
[OperationContract]
public Stream GetBlob(int id)
{
byte[] myBlob = GetBytesFromDatabase();
return new MemoryStream(myBlob);
}
}
如果您使用SQL Server 2008尝试直接发送流通过到WCF客户端
If you using SQL Server 2008 try sending the stream directly through to the WCF Client
[ServiceContract]
public class ContentService
{
[OperationContract]
public Stream GetBlob(int id)
{
return GetStreamFromDatabase(id);
}
}
请参阅使用WCF流式传输消息
这篇关于自定义流从MS-SQL读BLOBS - 我应该如何处理连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!