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

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...