Tuesday, December 2, 2014

WCF Windows Communication foundation

Windows communication Foundation and the important


Attributes used in WCF are

1.[DataContract] Used in the model class Customer information in this eg: Above the Class name you have to use this attribute.
[DataContract]
public class Customer
{
[DataMember]
public int Custid {get;set}
[DataMember]
public string CustName {get;set}
}

private List custList=new List()
{
new Customer()={Custid= 1,CustName ="Win"}
}

public List CustomerList
{
  get
  {
     return custList;
  }
}
2. Properties of the class are DataMembers
3.[ServiceContract] is an attribute used above the Interface
  [ServiceContract()]
    public interface ICustomer
    {
        [OperationContract]
        List< Customer > GetAllCustomerDetails();

        [OperationContract]
        Customer GetCustomer(int Id);
             

    }
4. [OperationContract] attributes above the interface methods. Interface methods are public by default 5. [WebGet] and .[WebInvoke] attributes can be used above the [OperationContract]
    [ServiceContract()]
    public interface ICustomer
    {
 [WebGet(UriTemplate = "Customer")]
        [OperationContract]
        List< Customer > GetAllCustomerDetails();
       [WebGet(UriTemplate = "GetCustomer?id={id}")]
        [OperationContract]
        Customer GetCustomer(int Id);
         [WebInvoke(Method = "POST", UriTemplate = "CustomerPOST")]
        [OperationContract]
        void AddCustomer(Customer newCust);    

    }

Step by step process here http://www.wcftutorial.net/How_to_create_RESTful_Service.aspx

No comments:

Post a Comment