Friday, 23 August 2013

DOTNET WCF OVERVIEW - MANOHAR GOUD TRAINER FACULTY GURU



Introduction to Windows Communication Foundation
 
There are a number of existing approaches to building distributed applications. These include Web services, .NET Remoting, Message Queuing (MSMQ) and COM+/Enterprise Services. Windows Communication Foundation (WCF) unifies these into a single framework for building and consuming services. Microsoft originally introduced WCF as part of the .NET Framework 3.0 and has continued to enhance it for the .NET Framework 3.5 and Visual Studio 2008. (For more information on WCF, drop by the portal site here: http://msdn.microsoft.com/en-us/netframework/aa663324.aspx).
 
In this series of tutorials, you’ll see how to use WCF to build distributed applications. This first tutorial introduces the basics of building, hosting and calling a WCF service. Along the way, you’ll learn the basics of WCF, including the role of endpoints, which consists of addresses, bindings and contracts. You’ll also see a variety of techniques you can use for controlling the behavior of your services. (These tutorials assume that you have Visual Studio 2008 installed, along with the .NET Framework 3.5. You can choose to work in either Visual Basic or C#--the steps listed here call out specific differences between the languages, when necessary.)
 
WCF is a unified programming model for building service-oriented applications. Before you build a WCF service, you will explore what that means.
 
Build Applications with a Unified Programming Model
Consider the following scenario. You are building a product management system. Basic product information, such as product name, description and price, is stored in a SQL Server database. You have built a front-end application to work with that data.
 
The distribution center, which is in the building next door, manages inventory. They have a server that hosts the Inventory database and a server that hosts the Inventory component you wrote to manage inventory. What technology will you use to talk to the Inventory component from your front -end application? They are on the same network, so you might choose to use .NET Remoting.
 
It is now a year later. Your company acquires another company and decides to merge the two distribution centers. The distribution center is now halfway across the country. Your first thought is to continue to use .NET Remoting and simply move the component to a different server.
 
However, you learn that you also need to make the Inventory component available to a variety of partners, not all of whom are using .NET applications. That rules out .NET Remoting. You could use .NET Remoting for internal clients and Web services for external clients. You could stop using .NET Remoting and use only Web services. Both of these options involve a significant rewrite and testing to upgrade a currently working application.
 
One of the primary motivations behind Windows Communication Foundation is to provide a single model for building distributed applications. If you built the Inventory component as a WCF service, your front-end could communicate using HTTP. If the distribution center moved back in house a year later, you could simply switch to using TCP. This change would be a simple configuration issue, not an architecture issue.
 
Build Service Oriented Applications
The application in this scenario is connected. The leading approach to building connected applications is service orientation. No doubt, you have heard of Service Oriented Architecture (SOA), but what is a service-oriented application?
 
A service is a program that performs a task and that a client application can communicate with through well-defined messages. To call a Web or WCF service, the client passes it a message, which consists of XML. The message will typically include a request for the service to perform an action, such as retrieve or update the inventory information for a product. If the service returns data to the client, it passes back a message, also consisting of XML.
 
The client and the service need to agree on what the XML will look like. The most common message format is Simple Object Access Protocol (SOAP). SOAP defines the format of XML request and reply messages and how clients and services encode the data in the messages.
 
In object-oriented programming, objects are tightly coupled. To call the Inventory component, a client application creates an instance of the component and therefore, controls its lifetime. In a service-oriented application, services and clients are loosely coupled. To call the Inventory service, a client does not instantiate an instance of a component. It simply passes a message to the service and may receive a message in return.
 
Service-oriented applications are loosely coupled. All communication occurs through messages. SOAP defines the format of messages. Contracts define the contents of messages. A service will publish a contract that specifies what methods clients can call, what arguments those methods take and what, if anything, the methods return. The contract can also specify security requirements and whether a transaction is required.
 
Why Use Windows Communication Foundation?
A distributed application built with Web services is a service-oriented application. ASP.NET Web Services (ASMX) has been available for building Web services since .NET was first released. Why then do you need Windows Communication Foundation? WCF provides a number of benefits over ASP.NET Web Services, including:
  • Support for sending messages using not only HTTP, but also TCP and other network protocols.
  • The ability to switch message protocols with minimal effort.
  • Support for hosting services on hosts other than a Web server.
  • Built-in support for the latest Web services standards (SOAP 1.2 and WS-*) and the ability to easily support new ones.
  • Support for security, transactions and reliability.
  • Support for sending messages using formats other than SOAP, such as Representational State Transfer (REST).

No comments:

Post a Comment