Windows Communication Foundation(WCF)

Introduction : "Windows Communication Foundation provides a unified framework for building secure and reliable transacted Web services. Windows Communication Foundation combines and extends the capabilities of Distributed Systems, Microsoft .NET Remoting, Web Services, and Web Services Enhancements (WSE), to develop and deliver unified secured systems. The WCF framework builds loosely-coupled applications on a service oriented architecture that interoperates more securely and reliably across platforms."
                                          
                                           it reduces the complexity of applications by unifying Enterprise Services, Messaging, .NET Remoting, Web Services, and WSE. WCF builds applications with an attributed programming model, leading to higher developer productivity. WCF was introduced as part of the .NET 3.0 Runtime components. The Windows Communication Foundation provides a service oriented programming model to build service oriented applications that interoperate across organizational and platform boundaries. It supports a broad range of Web Service standards like XML, XSD, SOAP, XPath, WSDL, and advanced standards and specifications like WS-Addressing, WS-Policy, WS-Security, WS-Trust, WS-Secure Conversation, WS-Reliable Messaging, WS-Atomic Transaction, WS-Coordination, and WS-Policy. 


                          
 


                                 Windows Communication Foundation


Components of WCF:
                                               A WCF Service is comprised of the following major components. The diagram below shows how the components are related to each other:
  • Service Contract
  • Operation Contract
  • Data Contract
  • Data Member

      Service Contract :
                                   A service contract is the gateway to a service for external applications to make use of the service functions, and at least one service contract should be available in a service. A service contract is defined as follows:

    Exj-
            
    [ServiceContract]
    public interface IStudentService
    {
        // Define the OperationContact here….
    }
    Note:  The ServiceContract attribute of the interface defines the service contract in the service interface. The service contract defines the operations available in the service, operations like web service methods in a web service. 
  •  
  • Operation Contract :
  •                                                 An operation contract defines the methods of the service that are accessible by external systems.The OperationContract attribute needs to be applied for all these methods, these are also like web methods in a web service. Operation contracts are defined as follows:

    Exj-

    [ServiceContract]
    public interface IStudentService
    {
          // Define the GetStudentFullName OperationContact here….
        [OperationContract]
        String GetStudentFullName (int studentId);

          // Define the GetStudentInfo OperationContact here….
        [OperationContract]
        StudentInformation GetStudentInfo (int studentId);

    }

    Data Contract :
                           A data contract defines a type with a set of data members or fields that will be used as the composite type in a service contract. It is a loosely-coupled model that is defined outside the implementation of the service and accessible by services in other platforms. To define a data contract, apply the DataContract attribute to the class to serialize the class by a serializer, and apply the DataMember attribute to the fields in the class that must be serialized. 

    Exj-
    [DataContract]
    public class StudentInformation
    {
        // Define the Datamembers here….
    }

    Data Member :
                                        A data member specifies the type which is part of a data contract used as a composite type member of the contract. To define a data member, apply the DataMember attribute to the fields that must be serialized. The DataMemberattribute can be applied to private properties, but they will be serialized and deserialized, and will be accessible to the user or process. The code below shows how to define a data member in a data contract:

    Exj-
    [DataContract]
    public class StudentInformation
    {
          _studentId = studId;

        [DataMember]
        public int StudentId
        {
            get { return _studentId; }
            set { _studentId = value; }
        }

    }