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›ABC of WCF, Restful services
    Enterprise Application DevelopmentTopic 33 of 37

    ABC of WCF, Restful services

    6 minread
    1,035words
    Intermediatelevel

    ABC of WCF (Windows Communication Foundation)

    WCF (Windows Communication Foundation) is a powerful framework for building service-oriented applications. It allows developers to create secure, reliable, and transacted web services that can communicate across different platforms and technologies. WCF is part of the .NET Framework and is highly flexible, allowing communication through multiple protocols and formats.

    Here’s the ABC of WCF to help you understand its core concepts:


    A - Address:

    In WCF, an Address is the location where the service is hosted and can be accessed by clients. The address is a URI (Uniform Resource Identifier) that points to the service endpoint.

    • The address defines where the service can be found.
    • It is used to specify the endpoint where the client will connect to access the service.
    • An endpoint in WCF consists of Address, Binding, and Contract.

    Example:

    <service name="CalculatorService">
        <endpoint address="http://localhost:8080/Calculator" 
                  binding="basicHttpBinding"
                  contract="ICalculatorService"/>
    </service>
    

    In the above example, http://localhost:8080/Calculator is the Address where the service is hosted.


    B - Binding:

    A Binding in WCF defines the communication mechanisms and protocols used to transmit messages between the client and the service. Bindings specify the transport protocols (e.g., HTTP, TCP), encoding (e.g., text, binary), and security features (e.g., SSL, authentication).

    • Common Bindings:
      • BasicHttpBinding: Common for interoperability with web services (SOAP-based).
      • NetTcpBinding: High-performance communication using TCP protocol for local services.
      • WsHttpBinding: Secure, reliable binding for service communication using SOAP over HTTP.
      • NetNamedPipeBinding: Used for high-performance communication on the same machine.

    Example:

    <bindings>
        <basicHttpBinding>
            <binding name="basicHttpBindingConfig">
                <security mode="None"/>
            </binding>
        </basicHttpBinding>
    </bindings>
    

    In the above configuration, basicHttpBinding is the Binding used for communication over HTTP.


    C - Contract:

    A Contract in WCF is a formal definition of the operations (methods) that a service exposes. It defines the interface or the contract that the service promises to fulfill. There are two main types of contracts in WCF:

    • Service Contract: Defines the operations a service provides.
      • Annotated using [ServiceContract] and [OperationContract] attributes.
    • Data Contract: Defines the data structures (classes) used to transfer data between the service and the client.
      • Annotated using [DataContract] and [DataMember] attributes.

    Example:

    [ServiceContract]
    public interface ICalculatorService
    {
        [OperationContract]
        int Add(int num1, int num2);
    }
    

    In the above example, ICalculatorService defines a Service Contract, and the Add method is an operation defined within this contract.


    Restful Services (RESTful Web Services)

    REST (Representational State Transfer) is an architectural style for building web services that operate over HTTP. RESTful services are simpler, lightweight, and more flexible compared to SOAP-based services like those in WCF. REST is widely used for creating APIs for web applications and mobile services.

    In RESTful services:

    • Each resource (e.g., data, objects) is represented by a URL.
    • Clients interact with resources using standard HTTP methods: GET, POST, PUT, DELETE.

    Unlike SOAP (used in WCF), REST does not rely on XML message formats. It typically uses JSON for data exchange, making it more lightweight and easier to integrate with web and mobile clients.


    Key Characteristics of RESTful Services:

    1. Stateless: Each request from a client to a server must contain all the information the server needs to fulfill the request. The server does not store any session information between requests.
    2. Client-Server: The client and server are separate entities. The client is responsible for the user interface, while the server manages resources.
    3. Uniform Interface: REST defines a uniform set of rules and conventions to interact with resources. This includes using standard HTTP methods like GET, POST, PUT, and DELETE.
    4. Cacheable: Responses from the server can be explicitly marked as cacheable or non-cacheable, helping to improve performance.

    Example of a RESTful Service (HTTP-based):

    Suppose we have a service that manages books. The service can provide access to books using these HTTP methods:

    • GET /books: Retrieves a list of books.
    • GET /books/{id}: Retrieves details of a specific book by ID.
    • POST /books: Adds a new book to the collection.
    • PUT /books/{id}: Updates an existing book by ID.
    • DELETE /books/{id}: Deletes a book by ID.

    In a RESTful service, a typical request to retrieve a book might look like:

    GET /books/1 HTTP/1.1
    Host: api.example.com
    

    The response could return the book details in JSON format:

    {
      "id": 1,
      "title": "Learning REST",
      "author": "John Doe",
      "year": 2025
    }
    

    Example of RESTful Service in WCF (using WebHttpBinding):

    You can build RESTful services using WCF by using WebHttpBinding, which allows WCF to expose RESTful services over HTTP.

    [ServiceContract]
    public class BookService
    {
        [OperationContract]
        [WebGet(UriTemplate = "books/{id}")]
        public Book GetBook(string id)
        {
            return new Book { Id = int.Parse(id), Title = "Learning REST", Author = "John Doe" };
        }
    }
    

    And in the configuration:

    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="webHttpBindingConfig"/>
            </webHttpBinding>
        </bindings>
        <services>
            <service name="BookService">
                <endpoint address="http://localhost:8080/books"
                          binding="webHttpBinding"
                          contract="BookService"
                          behaviorConfiguration="webHttpBehavior"/>
            </service>
        </services>
    </system.serviceModel>
    

    In this setup, WCF provides a RESTful service using WebHttpBinding. The WebGet attribute defines that the GetBook method can be called via a GET request.


    Summary of Key Concepts:

    • WCF ABC:

      • Address: The URI where the service can be accessed.
      • Binding: Defines the communication protocols and security settings.
      • Contract: Defines the operations and data that the service exposes.
    • Restful Services:

      • RESTful services are lightweight, use standard HTTP methods, and typically return data in JSON format.
      • They are stateless, client-server based, and have a uniform interface.
      • WCF can also be used to build RESTful services through WebHttpBinding.

    Both WCF and RESTful services are powerful tools for building service-oriented applications, with WCF offering a rich set of features (such as security, transactions, etc.) and REST providing a more lightweight and flexible approach for modern web applications.

    Previous topic 32
    Service contract, Data contract, XML, WCF bindings
    Next topic 34
    Consuming rest services (CRUD operations) using Jquery AJAX and JSON

    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,035
      Code examples0
      DifficultyIntermediate