ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalEC-332Wcf Fundamentals
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    EC-332

    Enterprise Application Development

    Progress0 / 37 done
    Topics37
    1Microsoft technology history2Introduction to .NET and its architecture3Concept of MSIL, CLR, CLS, CTS
    4Managed and Unmanaged Code5.Net Assembly6Introduction to C# fundamentals7Boxing and Unboxing8Implementing multi-tier architecture
    9SQL Injection, parameterized queries10Usage of data set, Data adapter and command builder in disconnected model
    11Multicast delegates12Introduction to windows forms13HTML
    14javascript and its data types, variables, functions15Debugging javascript using Firebug
    16Browser's Object (BOM), Document Object Model
    17Jquery effects
    18LINQ to Objects, LINQ to SQL19Query syntax, Operations (projection, filtering and join) using Linq Queries
    20The entity data model, CSDL21Eager vs lazy loading, POCO classes, DBContext API22Querying entity data models23Introduction to ASP.NET MVC24MVC application structure, Controllers overview25Action Methods, Parameterized action methods26Introduction to razor syntax27Code expressions, Code Blocks, Implicit Vs Explicit Code Expression28Data annotations, Client and Server Side Validation29Validation and model binding, Validation and model state30MVC Membership, Authorization and security
    31SOAP, WSDL32Service contract, Data contract, XML, WCF bindings33ABC of WCF, Restful services34Consuming rest services (CRUD operations) using Jquery AJAX and JSON35Introduction to web API36Example of web API using CRUD Example37MVC routing
    6 min read
    Topic 32 of 37
    Topic Study Note Illustration
    32

    Service contract, Data contract, XML, 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...

    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 view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    6mremaining
    1.0kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Enterprise Application Development