3
我的自定义WCF服务有一个用于从Sharepoint网站下载文件的方法。目标是调用DownloadFile然后接收流。从Sharepoint WCF流式传输
[OperationContract]
Stream DownloadFile(string uri);
用于提取从SharePoint文件和代码返回流是:
public Stream DownloadFile(string uri)
{
// NOTE! we cannot use a using statement as the stream will get closed.
var site = new SPSite(uri);
var web = site.OpenWeb();
var file = web.GetFile(uri);
// some custom authentication code...
// NOTE! do not close stream as we are streaming it.
return file.OpenBinaryStream();
}
我想这被流将自动获得正确关闭,并通过WCF服务配置为流媒体是流完成?
但是,我应该如何解决我的SharePoint对象没有正确处理(网站和网站)的问题?从长远来看这会是一个问题吗?有没有其他方法可用?我不想使用Sharepoint客户端对象模型,因为我在从Sharepoint下载文件时需要执行一些自定义验证代码。
任何想法或想法可能指向正确的方向?
UPDATE:
我可能会通过使用当前的OperationContext这样的OperationCompleted事件已经解决了这个:
OperationContext clientContext = OperationContext.Current;
clientContext.OperationCompleted += delegate
{
if(stream != null)
stream.Dispose();
site.Close();
web.Close();
};
也许我并不需要处置流?有没有人用上述方法看到有问题?
你的问题帮了我很多。与代表清理好主意。谢谢! – kenchilada