简体   繁体   English

如何通过网络服务流式传输文档?

[英]How can I stream documents via a webservice?

I am developing a broker service which accepts a clients request to search for an image with certain tags. 我正在开发一个代理服务,该服务接受客户请求以搜索带有某些标签的图像。 I have an existing web service in C# 2.0 which delivers the requested info and due to business rules, I cannot expose my 2.0 webservice to the new client and hence the need for my broker service which will invoke my 2.0 webservice and obtain the handle/location to the image and then try to stream it as the output of the WCF service call 我在C#2.0中已有一个现有的Web服务,该Web服务可以提供请求的信息,并且由于业务规则,我无法将我的2.0 Web服务公开给新客户端,因此需要代理服务来调用我的2.0 Web服务并获取句柄/位置到图像,然后尝试将其作为WCF服务调用的输出进行流传输

The images could be between 1MB to 20MB in size. 图像大小可能在1MB到20MB之间。 What is the best way to stream this data in WCF? 在WCF中流传输此数据的最佳方法是什么?

use MTOM attachments. 使用MTOM附件。 See this article for a comparison and explanation: http://msdn.microsoft.com/en-us/library/ms733742.aspx 请参阅本文以进行比较和解释: http : //msdn.microsoft.com/zh-cn/library/ms733742.aspx

Change your response type and write your file 更改您的回复类型并写入文件

Response.ContentType = "image/jpeg";

Response.WriteFile(fileNameAndPath);
Response.End();

alternatively if you have the image loaded in memory 或者,如果您已将图像加载到内存中

Response.ContentType = "image/jpeg";

Response.OutputStream.Write(imageBytes, 0, bytesLength);
Response.End();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM