Saturday, August 15, 2015

WCF Single (One way) contracts

Single Contract
Need to mark IsOneWay attribute true in operation contract to the service method that we want to execute in one way mode.
Its good practice to use one way for service methods returns void and methods having independent operations.
Benefit: Client code execution not halt (wait) till service method execution completes.

    [ServiceContract]
    public interface IService1
    {   
        [OperationContract(IsOneWay=true)]
        void SetData(int value);

    }
    public class Service1 : IService1
    {
        public void SetData(int value)
        {
            Thread.Sleep(value);
        }          
    }

Client Code:
    static void Main(string[] args)
    {
        SerDuplex.Service1Client _client = new SerDuplex.Service1Client();
        Console.WriteLine("Client execution started..." + DateTime.Now.ToString());
        _client.SetData(10000);
        Console.WriteLine("Client execution completed..." + DateTime.Now.ToString());
        Console.ReadLine();
    }
Results:











No comments:

Post a Comment

Node | Cluster Vs Worker Threads

Cluster: Multiple processes (scale app across CPU cores) Worker Threads: Multiple threads (handle CPU-heavy work inside one process) Cluster...