WCF tutorial | WCF Transfer mode
In our normal day today life, we need to transfer data from one location to other location. If data transfer is taking place through WCF service, message size will play major role in performance of the data transfer. Based on the size and other condition of the data transfer, WCF supports two modes for transferring messages
When the client and the service exchange messages, these messages are buffered on the receiving end and delivered only once the entire message has been received. This is true whether it is the client sending a message to the service or the service returning a message to the client. As a result, when the client calls the service, the service is invoked only after the client's message has been received in its entirety; likewise, the client is unblocked only once the returned message with the results of the invocation has been received in its entirety.
When client and Service exchange message using Streaming transfer mode, receiver can start processing the message before it is completely delivered. Streamed transfers can improve the scalability of a service by eliminating the requirement for large memory buffers. If you want to transfer large message, streaming is the best method.
In this mode of configuration, message send from client to service will be streamed
In this mode of configuration, message send from service to client will be streamed.
<service behaviorConfiguration="ServiceBehavior" name="MyService">
<endpoint address="" binding="netTcpBinding"
<endpoint address="mex" binding="mexHttpBinding"
<serviceDebug includeExceptionDetailInFaults="true "/>
transferMode="Buffered" closeTimeout ="0:01:00" openTimeout="0:01:00"></binding>
Differences between Buffered and Streamed Transfers
|Target can process the message once it is completely received.
||Target can start processing the data when it is partially received
|Performance will be good when message size is small
||Performance will be good when message size is larger(more than 64K)
|Native channel shape is IDuplexSessionChannel
||Native channels are IRequestChannel and IReplyChannel
- Always create the service with Interface->Implementation format, mention the contract in Interface.
- Define the service in Class library and refer the class library in Host project. Don’t use service class in host project.
- Change the instance mode to per call as default.
- Always catch exception using try/catch block and throw exception using FaultException < T >.
- Logging and Include exception should be enable while compiling the project in debug mode. While in production deployment disable the logging and Include exception details.