简体   繁体   English

取消具有大数据的WCF呼叫?

[英]Cancelling WCF calls with large data?

I'm about to implement a FileService using WCF. 我将使用WCF实现FileService。 It should be able to upload files by providing the filecontent itself and the filename. 通过提供文件内容本身和文件名,它应该能够上传文件。 The current ServiceContract looks like the following 当前的ServiceContract如下所示

[ServiceContract]
public interface IFileService
{
    [OperationContract]
    [FaultContract(typeof(FaultException))]
    byte[] LoadFile(string relativeFileNamePath);

    [OperationContract]
    [FaultContract(typeof(FaultException))]
    void SaveFile(byte[] content, string relativeFileNamePath);
}

It works fine at the moment, but i want to be able to reduce the network payload of my application using this Fileservice. 目前它工作正常,但我希望能够使用此Fileservice减少应用程序的网络有效负载。 I need to provide many files as soon as the user openes a specific section of my application, but i might be able to cancel some of them as soon as the user navigates further through the application. 用户打开我的应用程序的特定部分后,我需要提供许多文件,但是一旦用户进一步浏览该应用程序,我也许可以取消其中的一些文件。 As many of mine files are somewhere between 50 and 300 MB, it takes quite a few seconds to transfer the files (the application might run on very slow networks, it might take up a minute). 由于许多防雷文件的大小在50到300 MB之间,因此传输文件需要花费几秒钟的时间(该应用程序可能会在非常慢的网络上运行,可能需要一分钟时间)。

To clarify and to outline the difference to all those other WCF questions: The specific problem is that providing the data between client <-> server is the bottleneck, not the performance of the service itself. 澄清和概述与所有其他WCF问题的区别:具体问题是在客户端<->服务器之间提供数据是瓶颈,而不是服务本身的性能。 Is changing the interface to a streamed WCF service reasonable? 将接口更改为流式WCF服务是否合理?

It is a good practice to use a stream if the file size is above a certain amount. 如果文件大小超过一定数量,则使用流是一个好习惯。 At my work on the enterprise application we are writing, if it is bigger than 16kb then we stream it. 在编写企业应用程序时,我们正在编写,如果它大于16kb,则将其进行流式传输。 If it is less than that, we buffer. 如果小于该值,我们将缓冲。 Our file service is specially designed to handle this logic. 我们的文件服务是专门为处理这种逻辑而设计的。

When you have the transfer mode of your service set to buffer, it will buffer on the client as well as on the service when you are transmitting your data. 当您将服务的传输模式设置为缓冲时,它将在客户端和服务上在传输数据时缓冲。 This means if you are sending a 300mb file, it will buffer all 300mb during the call on both ends before the call is complete. 这意味着,如果您要发送300mb的文件,则它将在通话结束之前在两端的通话期间缓冲所有300mb的内容。 This will definitely create bottlenecks. 这肯定会造成瓶颈。 For performance reasons, this should only be when you have small files that buffer quickly. 出于性能原因,仅当您具有快速缓冲的小文件时才应如此。 Otherwise, a stream is the best way to go. 否则,流是最好的方法。

If the majority or all of your files are larger files I'd switch to using a stream. 如果您的文件中的大部分或全部是较大的文件,我会改用流。

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

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