Wednesday, December 12, 2012

Basics of WCF

Definition of WCF
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms.

WCF is a unified framework which provides :
1. NET Remoting 2.Distributed Transactions 3.Message Queues and 4.Web Services into a single service-oriented programming model for distributed computing.
WCF interoperate between WCF-based applications and any other processes that communicate via SOAP (Simple Object Access Protocol) messages

Features of WCF
  1. Service Orientation
  2. Interoperability
  3. Multiple Message Patterns
  4. Service Metadata
  5. Data Contracts
  6. Security
  7. Multiple Transports and Encodings
  8. Reliable and Queued Messages
  9. Durable Messages
  10. Transactions
  11. AJAX and REST Support
  12. Extensibility
Terms of WCF
A WCF service is exposed to the outside world as a collection of endpoints.
1. Endpoint: Endpoint is a construct at which messages are sent or received (or both). Endpoint comprises of ABC’s
What are ABC’s of WCF ?
A. Address - Address is a location that defines where messages can be sent
B. Binding - Binding is a specification of the communication mechanism (a binding) that described how messages should be sent
C. Contract - Contract is a definition for a set of messages that can be sent or received (or both) at that location (a service contract) that describes what message can be sent.
2. Service: A construct that exposes one or more endpoints, with each endpoint exposing one or more service operations.
3. Contracts: A contract is a agreement between two or more parties for common understanding and it is a is a platform-neutral and standard way of describing what the service does. In WCF, all services expose contracts.

Types of Contracts:
1) Operation Contract: An operation contract defines the parameters and return type of an operation.
2) Service Contract: Ties together multiple related operations contracts into a single functional unit.
3) Data Contract: The descriptions in metadata of the data types that a service uses

6 comments:

  1. Windows Communication Foundation (WCF) has an ASP.NET compatibility mode option to enable WCF applications to be programmed and configured like ASP.NET Web services, and mimic their behavior. Major Difference is That Web Services Use XmlSerializer But WCF Uses DataContractSerializer which is better in Performance as Compared to XmlSerializer. Key issues with XmlSerializer to serialize .NET types to XML * Only Public fields or Properties of .NET types can be translated into XML. * Only the classes which implement IEnumerable interface. * Classes that implement the IDictionary interface, such as Hash table can not be serialized. Important difference between DataContractSerializer and XMLSerializer. * A practical benefit of the design of the DataContractSerializer is better performance over Xmlserializer. * XML Serialization does not indicate the which fields or properties of the type are serialized into XML where as DataCotratSerializer Explicitly shows the which fields or properties are serialized into XML. * The DataContractSerializer can translate the HashTable into XML More thing we can host the WCF services in number of hosting applications, unlike Asp.net webservices, which support only iis hosting.

    ReplyDelete
  2. What is the difference between WCF and ASMX Web Services?


    Simple and basic difference is that ASMX or ASP.NET web service is designed to send and receive messages using SOAP over HTTP only. While WCF can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).

    ReplyDelete
  3. Web services can only be invoked by HTTP. While Service or a WCF component can be invoked
    by any protocol and any transport type. Second web services are not flexible. However, Services
    are flexible. If you make a new version of the service then you need to just expose a new end.
    Therefore, services are agile and which is a very practical approach looking at the current
    business trends.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. ASMX is simple but limited in many ways as compared to WCF.

    ASMX web services can be hosted only in IIS while WCF service has all the following hosting options:

    a. IIS
    b. WAS (Windows Process Activation Services)
    c. Console Application
    d. Windows NT Services
    e. WCF provided Host
    ASMX web services support is limited to HTTP while WCF supports HTTP, TCP, MSMQ, NamedPipes.
    ASMX Security is limited. Normally authentication and authorization is done using IIS and ASP.NET security configuration and transport layer security.For message layer security, WSE can be used.
    WCF provides a consistent security programming model for any protocol and it supports many of the same capabilities as IIS and WS-* security protocols, additionally, it provides support for claim-based authorization that provides finer-grained control over resources than role-based security.WCF security is consistent regardless of the host that is used to implement WCF service.
    Another major difference is that ASMX web services uses XmlSerializer for serialization while WCF uses DataContractSerializer which is far better in performance than XmlSerializer.
    Key Issues with XmlSerializer in serializing .NET types to xml are:

    a. Only public fields or properties of the .NET types can be translated to Xml.
    b. Only the classes that implement IEnumerable can be translated.
    c. Classes that implement IDictionary, such as Hashtable cannot be serialized.

    ReplyDelete
  6. What is the proxy for WCF Service?

    A proxy is a class by which a service client can Interact with the service.
    By the use of proxy in the client application we are able to call the different methods exposed by the service

    How can we create Proxy for the WCF Service?

    We can create proxy using the tool svcutil.exe after creating the service.
    We can use the following command at command line.
    svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config

    ReplyDelete