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
        }

    }

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