Docstoc

WCF Guide

Document Sample
WCF Guide Powered By Docstoc
					                                  WCF -
                                 Windows
                              Communication
                                Foundation
                                  Guide




TABLE OF CONTENT


    INTRODUCTION ..................................................................................... 2
    ADVANTAGES OF WCF ............................................................................ 3
    ADVANTAGES OF WCF SERVICE OVER WEB SERVICE ............................. 4
    VARIOUS WAYS OF HOSTING A WCF SERVICE ....................................... 5



Page 1 of 8             Clarion Technologies Pvt. Ltd, Pune                  Version 1.0
           o    MANAGED APPLICATION..................................................................... 5
           o    IIS ............................................................................................... 5
           o    WINDOWS SERVICE .......................................................................... 5
           o    WINDOWS ACTIVATION SERVICE......................................................... 5

    CREATING WCF SERVICE ....................................................................... 7
    USEFUL LINKS ....................................................................................... 8

INTRODUCTION

It is a part of the .NET Framework that provides a unified programming model for
rapidly building service-oriented applications that communicate across the web and the
enterprise.

Windows Communication Foundation (formerly code-named "Indigo") is a set of .NET
technologies for building and running connected systems. It is a new breed of
communications infrastructure built around the Web services architecture. Advanced
Web services support in Windows Communication Foundation provides secure, reliable,
and transacted messaging along with interoperability. The service-oriented
programming model of Windows Communication Foundation is built on the Microsoft
.NET Framework and simplifies development of connected systems. Windows
Communication Foundation unifies a broad array of distributed systems capabilities in
a composable and extensible architecture, spanning transports, security systems,
messaging patterns, encodings, network topologies, and hosting models.

The global acceptance of Web services, which includes standard protocols for
application-to-application communication, has changed software development. For
example, the functions that Web services now provide include security, distributed
transaction coordination, and reliable communication. The benefits of the changes in
Web services should be reflected in the tools and technologies that developers use.
Windows Communication Foundation (WCF) is designed to offer a manageable
approach to distributed computing, broad interoperability, and direct support for
service orientation.

WCF simplifies development of connected applications through a new service-oriented
programming model. WCF supports many styles of distributed application development
by providing a layered architecture. At its base, the WCF channel architecture provides
asynchronous, untyped message-passing primitives. Built on top of this base are
protocol facilities for secure, reliable, transacted data exchange and broad choice of
transport and encoding options.

The typed programming model (called the service model) is designed to ease the
development of distributed applications and to provide developers with expertise in
ASP.NET Web services, .NET Framework remoting, and Enterprise Services, and who
are coming to WCF with a familiar development experience. The service model features
a straightforward mapping of Web services concepts to those of the .NET Framework
common language runtime (CLR), including flexible and extensible mapping of
messages to service implementations in languages such as Visual C# or Visual Basic. It



Page 2 of 8              Clarion Technologies Pvt. Ltd, Pune                         Version 1.0
includes    serialization facilities that enable loose coupling and versioning, and it
provides    integration and interoperability with existing .NET Framework distributed
systems     technologies such as Message Queuing (MSMQ), COM+, ASP.NET Web
services,   Web Services Enhancements (WSE), and a number of other functions.




ADVANTAGES OF WCF

Because WCF can communicate using Web services, interoperability with other
platforms that also support SOAP, such as the leading J2EE-based application servers,
is straightforward.

You can also configure and extend WCF to communicate with Web services using
messages not based on SOAP, for example, simple XML formats like RSS.

Performance is of paramount concern for most businesses. WCF is developed with the
goal of being one of the fastest distributed application platform developed by Microsoft.

To allow optimal performance when both parties in a communication are built on WCF,
the wire encoding used in this case is an optimized binary version of an XML
Information Set. Messages still conform to the data structure of a SOAP message, but
their encoding uses a binary representation of that data structure rather than the
standard angle-brackets-and-text format of the XML 1.0 text encoding. Using this
option makes sense for communicating with the call center client application, because
it is also built on WCF, and performance is an important concern.

Managing object lifetimes, defining distributed transactions, and other aspects of
Enterprise Services are now provided by WCF. They are available to any WCF-based
application, which means that the rental car reservation application can use them with
any of the other applications it communicates with.

Because it supports a large set of the WS-* specifications, WCF helps provide
reliability, security, and transactions when communicating with any platform that also
supports these specifications.

The WCF option for queued messaging, built on Message Queuing, allows applications
to use persistent queuing without using another set of application programming
interfaces.

WCF can     maintain transaction like COM+ Does
  1. It     can maintain state
  2. It     can control concurrency
  3. It     can be hosted on IIS, WAS, Self hosting, Windows services




Page 3 of 8            Clarion Technologies Pvt. Ltd, Pune       Version 1.0
It has AJAX Integration and JSON (JavaScript object
notation) supportADVANTAGES OF WCF SERVICE OVER WEB SERVICE

   WCF supports more of the WS-* standards than Web Services. You can’t really do
   streaming or support atomic transactions etc in Web Services. WCF supports
   multiple binding’s HTTP, WSHTTP, TCP, MSMQ etc. ASP.NET Web Services has only
   http.


   Web Services have no instance management, i.e. you cannot have a singleton web
   service, or a session-full web service. You can maintain state of web services but
   we all know how painful that is.


   WCF while very similar to Web Services also incorporates many of the features of
   Remoting and .NET Enterprise Services (COM+ Services Components).


   Web services can only be invoked by HTTP (traditional WebService with .asmx).
   While WCF Service or a WCF component can be invoked by any protocol (like http,
   tcp etc.) and any transport type.


   Web services are not flexible. However, WCF 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.




Page 4 of 8         Clarion Technologies Pvt. Ltd, Pune       Version 1.0
VARIOUS WAYS OF HOSTING A WCF SERVICE


To become active, a service must be hosted within a run-time environment that
creates it and controls its context and lifetime. Windows Communication Foundation
(WCF) services are designed to run in any Windows process that supports managed
code.
Fortunately, WCF provides various options when it comes to hosting a service. These
options are:

1.    Managed application
      WCF services can be hosted in any managed application. This is the most
      flexible option because it requires the least infrastructure to deploy. You embed
      the code for the service inside the managed application code and then create
      and open an instance of the ServiceHost to make the service available.

2.    IIS
      The IIS hosting option is integrated with ASP.NET and uses the features these
      technologies offer, such as process recycling, idle shutdown etc. On the
      Windows XP and Windows Server 2003 operating systems, this is the preferred
      solution for hosting Web service applications that must be highly available and
      highly scalable. IIS also offers the integrated manageability that customers
      expect from an enterprise-class server product. This hosting option requires
      that IIS be properly configured, but it does not require that any hosting code be
      written as part of the application.

3.    Windows service
      This hosting option consists of registering the application domain (AppDomain)
      that hosts an WCF service as a managed Windows Service (formerly known as
      NT service) so that the process lifetime of the service is controlled by the
      service control manager (SCM) for Windows services. Like the self-hosting
      option, this type of hosting environment requires that some hosting code is
      written as part of the application. The service is implemented as both a
      Windows Service and as a WCF service by causing it to inherit from the
      ServiceBase class as well as from a WCF service contract interface. The
      ServiceHost is then created and opened within an overridden OnStart method
      and closed within an overridden OnStop method. This hosting option provides
      us long-running WCF service hosted outside of IIS in a secure environment that
      is not message-activated. The lifetime of the service is controlled instead by the
      operating system.

4.    Windows Activation Service.
      Windows Process Activation Service (WAS) is the new process activation
      mechanism for the Windows Server 2008 that is also available on Windows
      Vista. It retains the familiar IIS 6.0 process model (application pools and
      message-based process activation) and hosting features (such as rapid failure
      protection, health monitoring, and recycling), but it removes the dependency on




Page 5 of 8         Clarion Technologies Pvt. Ltd, Pune         Version 1.0
       HTTP from the activation architecture. IIS7.0 uses WAS to accomplish message-
       based activation over HTTP.
The choice of the host restricts the type of transport that you can use for that service.
Here is the summary of hosting options and supported features.

Feature                            Self-Hosting       IIS Hosting      WAS Hosting
Executable Process/ App Domain Yes                    Yes              Yes
Configuration                      App.config         Web.config       Web.config
Activation                         Manual at startup Message-based Message-based
Idle-Time Management               No                 Yes              Yes
Health Monitoring                  No                 Yes              Yes
Process Recycling                  No                 Yes              Yes
Management Tools                   No                 Yes              Yes




Page 6 of 8          Clarion Technologies Pvt. Ltd, Pune           Version 1.0
CREATING WCF SERVICE


   1. Open the Microsoft Visual Studio 2008
   2. Click File -> New -> Project -> WCF Service Application
   3. Create service as per your requirements.
   4. For creating client application, click File -> New -> Project -> ASP.Net Web
      Application
   5. Create the project in the same solution as of service.
   6. Add reference to the service as follows:
          a. Click Project -> Add Service Reference
          b. Click “Discover” and you will get the services in the current solution.
          c. Click Ok.
   7. To use the service, see the example code below:

ServiceReference2.SubjectClient objSClient = new
ServiceReference2.SubjectClient();
ServiceReference2.SubjectDetails objSDetails =
(ServiceReference2.SubjectDetails)objSClient.GetData(txtSubjectCode.Text);



   Find the Zipped code of a test WCF site and the client application of it’s use by
   clicking here.




Page 7 of 8          Clarion Technologies Pvt. Ltd, Pune          Version 1.0
USEFUL LINKS

Useful Videos for WCF

Hosting WCF in IIS

Hosting WCF in Windows service

Wikipedia link for WCF

MSDN Information for WCF




Page 8 of 8          Clarion Technologies Pvt. Ltd, Pune   Version 1.0

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:10
posted:2/8/2012
language:Latin
pages:8