Understanding Message Exchange Patterns (MEP) in WCF

Understanding Message Exchange Patterns (MEP) in WCF

29 Jul 2025
Intermediate
72.9K Views
3 min read
Learn with an interactive course and practical hands-on labs

Free .NET Microservices Online Course - Beginners Start Here

Message Exchange Patterns describes the way of communication between Client and Server means how client and server would be exchange messages to each other. There are three types of message exchange patterns

  1. Request-Reply

    In this communication, client sends the message to the service and waits for reply from the service. Within a ReceiveTimeout period (default timeout is one minute), if the service doesn't respond to the client then the client will receive a TimeoutException. In this pattern, client waits for the reply mes-sage, even if the service operation's return type is void.

    Request-Reply

    This the by default message exchange pattern in WCF. All WCF bindings except MSMQ-based bindings supports this pattern.

    [ServiceContract]
    public interface RequestReplyService
    { 
     [OperationContract]
     string GetData(int value);
    
     [OperationContract(IsOneWay = false)]
     void SaveData(string value);
    }
    

    To define this pattern, you can set IsOneWay property to false explicitly, but by default it is false. So there is need to define ISOneWay property for Request-Reply pattern. A Request-Reply operation returns header with an HTTP status code of 200 (OK) and a full SOAP response in the message body.

  2. One-Way

    In this communication, client sends the message to the service and doesn't wait for reply from the service. In this pattern, receiver doesn’t send any response to the sender, even if any error occurs in the communication.

    One-way

    This pattern doesn’t supports output parameters, by-reference parameters and return value to an operation, otherwise you will receive an InvalidOperationException.

    All of the WCF bindings support one-way operations.

    [ServiceContract]
    public interface OneWayService
    {
     [OperationContract(IsOneWay = true)]
     void SaveData(string value);
    }
    

    A One-Way operation returns only header with an HTTP status code of 202 (Accepted) without message body. This pattern is commonly used with per-call or singleton services only.

  3. Duplex

    In this communication, client and services can sends messages to each other by using One-way or request-reply messaging.

    DuplexDuplex

    Only bidirectional-capable bindings support this pattern like as WS Dual, TCP and IPC bindings.

    To make a duplex contract, you must also define a callback contract and assign the typeof that callback con-tract to the CallbackContract property of your service contract’s ServiceContract attribute as shown in be-low example.

     
    [ServiceContract(CallbackContract = typeof(DuplexServiceCallback))]
    public interface DuplexService
    {
     [OperationContract(IsOneWay = true)] //One-Way
     void SaveData();
    
     [OperationContract] //Request-Reply.
     string GetData();
     }
    
     public interface DuplexServiceCallback
     {
     [OperationContract(IsOneWay = true)]
     void Progress(string status);
     }
    

    For this pattern, you must also specified the binding as wsDualHttpBinding with in your web.config as shown below-

    <services>
     <service name="WCFServiceApp.DuplexService">
     <endpoint address ="" binding="wsDualHttpBinding" con-tract="WCFServiceApp.IDuplexService">
     </endpoint>
     </service>
    </services>
    
    What do you think?

    I hope you will enjoy the tips while programming with WCF. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

He is a renowned Speaker, Solution Architect, Mentor, and 10-time Microsoft MVP (2016–2025). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.
Live Training - Book Free Demo
Azure AI Engineer Certification Training
20 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Azure AI & Gen AI Engineer Certification Training Program
20 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Advanced Full-Stack .NET Developer with Gen AI Certification Training
21 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
ASP.NET Core Certification Training
21 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
Azure DevOps Certification Training
24 Sep
08:30PM - 10:30PM IST
Checkmark Icon
Get Job-Ready
Certification
Accept cookies & close this