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 Advanced
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 33 of 37
    Topic Study Note Illustration
    33

    ABC of WCF, Restful services

    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...

    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 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