Friday, July 15, 2016

Type of Contracts

There are two types of contracts
  1. Behavioral Contract
  2. Structural Contract
Behavioral Contract:
    1. Service Contract
    2. Operation Contract
    3. Fault Contract
Structural Contract:
    1. Data Contract
    2. Message Contract
Message Contract: Developer mostly uses DataContract but whenever we require more control over soap message MessageContract comes into picture.
Using MessageContract you can define header and body members of soap message that wcf inserts in soap message.

Note: When using message contract with a operationcontract
Either only messagecontract can be used as parameter and return value or nothing as parameter or return type.

[MessageContract]
    public class UserInfoRequestMessage
    {
        [MessageHeader()]
        public string UserAuthCode;

        [MessageBodyMember()]
        public int UserId;
    }

    [MessageContract]
    public class UserInfoResponseMessage
    {
        [MessageBodyMember()]
        public UserInfo MyUserInfo;
    }

    [ServiceContract]
    public interface IUserService
    {
        [OperationContract]
        UserInfoResponseMessage GetUserById(UserInfoRequestMessage usrInfoMessage);
    }

    public class UserService : IUserService
    {
        public UserInfoResponseMessage GetUserById(UserInfoRequestMessage usrInfoMessage)
        {
            //Method implementation
        }

    }

Friday, July 1, 2016

Virtual Vs Abstract

Differences between Abstract & Virtual functions -

Members
  • Abstract function doesn't contain any body but a virtual function contain body 
  • We must be implement the abstract function in derived class but it is not necessary for virtual function 
  • Abstract function can only use in abstract class but it is not necessary for virtual function 
  • Abstract function are called pure virtual function
  • It must be a function member. That is, fields and constants cannot be abstract members.

    Class
    • You cannot create instances of an abstract class.
    • An abstract class is declared using the abstract modifier
    • An abstract class can contain abstract members or regular, nonabstract members.
    • An abstract class can itself be derived from another abstract class
    • Any class derived from an abstract class must implement all the abstract members of the class by using the override keyword, unless the derived class is itself abstract.

    abstract class Helloworld
    {
        public int Int1 { get; set; } //Non Abstract property

        public abstract int Int2  //Abstract Property
        {
            get;
            set;
        }

        public  Helloworld()  //Constructor
        {
            Console.WriteLine("Helloworld Constructor");
        }

        public void Method1()   //Non Abstract Method
        {
            Console.WriteLine("Helloworld Method1");
        }

        public abstract void Method2();  //Abstract Method

         ~Helloworld()  //Destructor
        {
            Console.WriteLine("Helloworld Destructor");
        }
    }

    class Drived : Helloworld
    {
        public int Val;
        public override int Int2
        {
            get
            {
                return Val;
            }
            set
            {
                Val=value;
            }
        }

        public override void Method2()
        {
            Console.WriteLine("Drived Method2");
        }
    }
    class Program
    {
        static unsafe void Main(string[] args)
        {

            Drived Dr = new Drived();
            Dr.Int1 = 10;
            Dr.Int2 = 20;
            Dr.Method1();
            Dr.Method2();
            Console.ReadLine();
        }
    }

    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...