WSE3.0 Framework provides data optimization transport mechanism, WSE3.0 build Web Service Security (4): Mtom message transmission optimization and file upload, download questions are introduced. WCF also provides streaming operations to support the transfer and processing optimization of large data objects, and today we WCF distributed development Step-win series (4): Use flow operations (streaming Operations) to optimize transmission. This section details the concepts involved in streaming operations, the programming implementation process, and some of the major issues that need to be developed during the actual development process. This section structure: "1" Stream processing Concept "2" Flow Processing Features "3" Sample Code Analysis "4" summary. Finally upload the sample code for this article.
Streaming, the translation of this text into stream processing (programming WCF services, translated by Brother Zhang Yi), is not controversial. I choose "flow processing" the meaning of the word, just want to make this streaming word image accurate, moving nouns, streaming processing, flow processing, translation for streaming operations, beginners will misunderstand that this is a service operation. Because streaming is just a mechanism built in WCF. Rather than an operation. )
We first understand what is streaming flow processing.
The concept of "1" streaming flow processing:
Typically, the client interacts with the server to deliver the message, both on the receiving side of the cache, pending receipt and processing. This is true regardless of whether the receiving end is a client or a server.
"1.1" To solve the problem:
When the client invokes the service, it blocks the client process until the message is sent, the server starts processing the data, and then returns the processed results to the client, which can be unblocked before it is received. The problem is that when the message is delivered in a short time, the relative processing time is negligible and the efficiency of the system service is not affected. But if the message data is large, such as pictures or multimedia objects. Each transmission time is relatively large, so that the receiver's waiting time is too long, it is bound to be a long time, the process can not continue execution. Thus resulting in inefficiency.
"1.2" Streaming flow processing:
Streaming flow processing is a kind of optimization mechanism provided by WCF for a large number of message data processing. WCF allows the receiver to receive messages through the channel while initiating processing of the message data, which is called the streaming transport model.
The characteristics of "2" Streaming flow treatment:
Obviously, the flow processing mechanism improves the throughput and response efficiency of the system in terms of processing a large number of message data.
"2.1" Stream processing operation definition:
WCF's streaming mechanism needs to use the stream class defined by the. NET Framework (It is FileStream, NetworkStream, MemoryStream's parent Class). Stream processing applies the scenario:
[ServiceContract]
interface IMyContract
{
[OperationContract]
Stream StreamReply1( );
[OperationContract]
void StreamReply2(out Stream stream);
[OperationContract]
void StreamRequest(Stream stream);
[OperationContract(IsOneWay = true)]
void OneWayStream(Stream stream);
}
It can be used as a type of return data, parameters, and output parameters. Of course, it can be used as a monotone service operation parameter. The parameters used here must be serializable, such as MemoryStream. FileStream does not support serialization and therefore cannot be used as a parameter or to return a type of data.