ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Enterprise Application Development
    EC-332
    Progress0 / 37 topics
    Topics
    1. Overview of Enterprise Application Development: Microsoft technology history2. Introduction to .NET and its architecture3. Concept of MSIL, CLR, CLS, CTS4. Introduction to .NET framework: Managed and Unmanaged Code5. .Net Assembly6. Introduction to C# fundamentals7. Boxing and Unboxing8. Implementing multi-tier architecture9. Introduction to ADO.Net: SQL Injection, parameterized queries10. Usage of data set, Data adapter and command builder in disconnected model11. Introduction to delegate: Multicast delegates12. Introduction to windows forms13. HTML14. Introduction to javascript: javascript and its data types, variables, functions15. Debugging javascript using Firebug16. Introduction to various object models: Browser's Object (BOM), Document Object Model17. Introduction to Jquery: Jquery effects18. Introducing LINQ: LINQ to Objects, LINQ to SQL19. Query syntax, Operations (projection, filtering and join) using Linq Queries20. Introduction to ADO.NET entity framework: The entity data model, CSDL21. Eager vs lazy loading, POCO classes, DBContext API22. Querying entity data models23. Introduction to ASP.NET MVC24. MVC application structure, Controllers overview25. Action Methods, Parameterized action methods26. Introduction to razor syntax27. Code expressions, Code Blocks, Implicit Vs Explicit Code Expression28. Data annotations, Client and Server Side Validation29. Validation and model binding, Validation and model state30. MVC Membership, Authorization and security31. Introduction to service-oriented architecture: SOAP, WSDL32. Service contract, Data contract, XML, WCF bindings33. ABC of WCF, Restful services34. Consuming rest services (CRUD operations) using Jquery AJAX and JSON35. Introduction to web API36. Example of web API using CRUD Example37. MVC routing
    EC-332›Service contract, Data contract, XML, WCF bindings
    Enterprise Application DevelopmentTopic 32 of 37

    Service contract, Data contract, XML, WCF bindings

    6 minread
    1,017words
    Intermediatelevel

    Service Contract, Data Contract, XML, and WCF Bindings

    In Windows Communication Foundation (WCF), which is a framework for building service-oriented applications, key concepts like Service Contract, Data Contract, XML, and WCF Bindings play a central role in defining how services communicate, exchange data, and how these interactions are structured.

    Let's break down these concepts:


    1. Service Contract:

    A Service Contract in WCF is an interface or a set of operations (methods) that define what the service does. It acts as the contract or agreement between the service provider (the server) and the service consumer (the client). This contract defines the methods that can be called, the input and output parameters, and the exception handling.

    • Key Points:
      • A Service Contract is defined using the [ServiceContract] attribute.
      • Each method that can be called by the client is defined using the [OperationContract] attribute.
      • The ServiceContract specifies what operations are available to be invoked on the service.

    Example of a Service Contract:

    [ServiceContract]
    public interface ICalculatorService
    {
        [OperationContract]
        int Add(int num1, int num2);
    
        [OperationContract]
        int Subtract(int num1, int num2);
    }
    
    • Explanation:
      • The ICalculatorService interface defines a service contract with two operations: Add and Subtract.
      • The [ServiceContract] attribute declares that this interface is a service contract.
      • Each operation, like Add and Subtract, is annotated with the [OperationContract] attribute.

    2. Data Contract:

    A Data Contract in WCF is a formal agreement between the service and the client regarding the structure of the data that will be exchanged. It defines the shape of the data that is sent and received by the service. This contract ensures that both the service and client agree on how the data will be serialized and deserialized.

    • Key Points:
      • A Data Contract is defined using the [DataContract] attribute.
      • Each data member (property or field) to be serialized is marked with the [DataMember] attribute.
      • It ensures compatibility between different systems by defining the data structure in a standard way.

    Example of a Data Contract:

    [DataContract]
    public class Customer
    {
        [DataMember]
        public int CustomerId { get; set; }
    
        [DataMember]
        public string Name { get; set; }
    
        [DataMember]
        public string Email { get; set; }
    }
    
    • Explanation:
      • The Customer class defines a data contract.
      • The [DataContract] attribute marks the class as a data contract.
      • The [DataMember] attribute is applied to each property that needs to be serialized and sent over the network.

    3. XML in WCF:

    In WCF, XML plays an important role because data is typically transmitted in XML format over the wire. Both the service and the client exchange data using XML-encoded messages. WCF uses SOAP (Simple Object Access Protocol) as the default messaging format, which is XML-based.

    • Key Points:
      • SOAP messages are formatted in XML and include a header and a body.
      • WCF messages, whether they are requests or responses, are serialized into XML when they are sent across the network.
      • XML provides a platform-independent, language-neutral way to represent data.

    Example of XML Message in WCF (SOAP message):

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                      xmlns:web="http://www.example.com/webservice">
       <soapenv:Header/>
       <soapenv:Body>
          <web:Add>
             <web:num1>5</web:num1>
             <web:num2>3</web:num2>
          </web:Add>
       </soapenv:Body>
    </soapenv:Envelope>
    
    • Explanation:
      • This is an example of a SOAP message, where the body contains the operation (Add) and the parameters (num1 and num2).
      • The SOAP message is XML-encoded and can be parsed by both the client and the service, regardless of the programming language used.

    4. WCF Bindings:

    WCF Bindings define how the service communicates with the client. A binding is a set of protocols and transport mechanisms used for communication between the client and the service. It determines how the service should be accessed, the format of the messages, and the transport protocol (e.g., HTTP, TCP).

    WCF provides several built-in bindings that cater to different communication scenarios:

    • BasicHttpBinding: Uses HTTP and is compatible with SOAP-based web services. It’s the most commonly used binding for interoperability with other web services (like ASMX).
    • NetTcpBinding: Uses TCP for communication and is optimized for high-performance communication between WCF services within the same network.
    • WsHttpBinding: A secure, reliable, and interoperable binding that is commonly used in enterprise applications.
    • NetNamedPipeBinding: Used for communication between services on the same machine. It is fast and secure but works only for local communication.
    • NetMsmqBinding: Uses MSMQ (Microsoft Message Queuing) for communication, suitable for asynchronous messaging.

    Example of Binding Configuration (Web.config):

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="basicHttpBindingConfig">
                    <security mode="None"/>
                </binding>
            </basicHttpBinding>
        </bindings>
    
        <services>
            <service name="CalculatorService">
                <endpoint address="" 
                          binding="basicHttpBinding" 
                          bindingConfiguration="basicHttpBindingConfig"
                          contract="ICalculatorService"/>
            </service>
        </services>
    </system.serviceModel>
    
    • Explanation:
      • In this example, we use basicHttpBinding for communication between the client and the service.
      • The <security mode="None"/> indicates no security (but this can be configured for more secure communications).
      • The ICalculatorService contract is exposed by the CalculatorService service.

    Summary of Key Concepts:

    1. Service Contract: Defines the operations (methods) that a service exposes. It is marked with the [ServiceContract] attribute, and each method is marked with the [OperationContract] attribute.
    2. Data Contract: Defines the structure of the data exchanged between the service and the client. It is marked with the [DataContract] attribute, and individual properties are marked with the [DataMember] attribute.
    3. XML: WCF uses XML for message formatting (typically in the SOAP protocol) for platform-agnostic data exchange.
    4. WCF Bindings: Specify the communication protocols and message formats used between the client and the service. Some common bindings include BasicHttpBinding, NetTcpBinding, and WsHttpBinding.

    By using Service Contracts, Data Contracts, XML messages, and Bindings, WCF provides a robust and flexible platform for building distributed, service-oriented applications that can communicate across platforms.

    Previous topic 31
    Introduction to service-oriented architecture: SOAP, WSDL
    Next topic 33
    ABC of WCF, Restful services

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time6 min
      Word count1,017
      Code examples0
      DifficultyIntermediate