Ramani Sandeep's Blog

DotNetting – Fast , Easy Way of Developing Applications

Archive for the ‘WCF’ Category

Web Service Vs WCF

Posted by Ramani Sandeep on November 12, 2009

Introduction

ASP.NET Web services were developed for building applications that send and receive messages by using the Simple Object Access Protocol (SOAP) over HTTP. The structure of the messages can be defined using an XML Schema, and a tool is provided to facilitate serializing the messages to and from .NET Framework objects. The technology can automatically generate metadata to describe Web services in the Web Services Description Language (WSDL), and a second tool is provided for generating clients for Web services from the WSDL.

WCF is for enabling .NET Framework applications to exchange messages with other software entities. SOAP is used by default, but the messages can be in any format, and conveyed by using any transport protocol. The structure of the messages can be defined using an XML Schema, and there are various options for serializing the messages to and from .NET Framework objects. WCF can automatically generate metadata to describe applications built using the technology in WSDL, and it also provides a tool for generating clients for those applications from the WSDL.

Protocol Support

WCF Supports following protocol: HTTP, TCP, Named Pipes, MSMQ, Custom, UDP.

Web Service Support only HTTP Protocol.

Hosting Support

Web Service can be hosted only with Http Runtime on IIS. WCF component can be hosted in any kind of environment in .NET 3.0, such as a console application, Windows application, or IIS.

WCF services are known as ’services’ as opposed to web services because you can host services without a web server.

Self-hosting the services gives you the flexibility to use transports other than HTTP.

Backwards Compatibility

The purpose of WCF is to provide a unified programming model for distributed applications.

WCF takes all the capabilities of the existing technology stacks while not relying upon any of them.

Applications built with these earlier technologies will continue to work unchanged on systems with WCF installed.

Existing applications are able to upgrade with WCF

Integration

WCF can use WS-* or HTTP bindings to communicate with ASMX pages

Advantage of WCF or Limitations of ASMX

An ASMX page doesn’t tell you how to deliver it over the transports and to use a specific type of security. This is something that WCF enhances quite significantly.

ASMX has a tight coupling with the HTTP runtime and the dependence on IIS to host it. WCF can be hosted by any Windows process that is able to host the .NET Framework 3.0.

ASMX service is instantiated on a per-call basis, while WCF gives you flexibility by providing various instancing options such as Singleton, private session, per call.

ASMX provides the way for interoperability but it does not provide or guarantee end-to-end security or reliable communication.

Reference : http://msdn.microsoft.com/en-us/library/aa702755.aspx

Posted in WCF, Web Services | Tagged: , , , | 1 Comment »

What is Windows Communication Foundation?

Posted by Ramani Sandeep on July 21, 2009

.NET 3.0 comes with three main technologies in core: Windows Presentation Foundation, Windows Workflow Foundation and Windows Communication Foundation.

Windows Communication Foundation (WCF), codenamed Indigo in Microsoft, is the last generation of service oriented technologies for development.  It provides all the latest means to help developers build service oriented applications.  The result of service oriented design is a distributed system which runs between services and clients.  Windows Communication Foundation is Microsoft infrastructure for Service Oriented architecture.

You have probably worked with Web Services in .NET 1.x or 2.0 and may have some experiences with Remoting.  Windows Communication Foundation is an enhanced technology to provide the same functionality with better features and reduces the time to develop a distributed system.  Web Services and Services are not identical.  One main difference is Web Services use HTTP protocol, but Services can use any protocol and this is an important difference.

Service Orientation

In recent years, development moved from building centralized local systems to distributed systems which run on several places.  Each part of these systems are hosted somewhere and provide some services.  The idea of having services to answer to common needs through the web became serious and development technologies answered to this need by providing Web Services in their core, but day after day distributed systems became more common and the idea of Service Orientation (SO) was born.

Service Orientation is a complement to Object Orientation.  It means you will not kick Object Orientation out to use Service Orientation.  Service Orientation uses Object Orientation in its core, but there are some distributed scenarios that can be viewed by Object Orientation so you use Service Orientation to describe these scenarios.

In Service Orientation you think different and describe things via services and divide your system into smaller parts which run as services.  These services can communicate with others via messages.  In each service you can apply Object Orientation to accomplish goals of that service.  One important benefit of Service Orientation is here because you can use different technologies and platforms to design a service by using Object Orientation then use universal formats to build messages and start communication between different pieces of your system.

There are four principles in Service Orientation (you may see them as tenets on other resources):

  • Boundaries are explicit.
  • Services are autonomous.
  • Services share schema and contract, not class.
  • Service compatibility is determined based on policy.

You can read more about these fundamentals (they are important principles) on MSDN.

Generally, you have to change your point of view in Service Oriented design, but this should not change your view for Object Oriented Programming.  You should get enough experience to divide a system to logical independent services then choose appropriate platform to build each piece.  Thankfully, Microsoft helps you in all stages and you can use powerful Microsoft technologies to build your distributed software.

Service Oriented Architecture (SOA) is a concept beyond the scope of these tutorials.  I recommend you to read good books about Service Oriented Architecture to learn more about it.  Having a good understanding of this architecture is an important requirement to be success in this field.

Advantages

Windows Communication Foundation has some important enhancements in comparison with preceding technologies.

  • It merges all older separate technologies in one place and allows you to do things easier.
  • It has rich communication capabilities.
  • It comes with many powerful and ready to use enterprise features.
  • It can be integrated with other technologies and has great interoperability.

Architecture

Architecture of Windows Communication Foundation consists of five layers.  These layers from top to down are:

  • Application  : In this level application is located.
  • Contracts    : In the second layer service, data and message contracts as well as bindings and policies are present.  In this level services describe themselves to clients.
  • Runtime     : Behaviors are located in this layer.  Runtime layer loads all services.
  • Messaging  : Different types of channels as well as encoders are here.  This layer enables communications for services.
  • Hosting  : This layer is where host services in different manners, but there are two common ways to host a service.  You can host a service in Internet Information Services (IIS) which is easier than the second approach and starts and stops your services automatically.  The second approach is to create executable files (.EXE) for services and start and stop them manually by writing more codes.

This layering allows developers to work on Windows Communication Foundation with different skills because each layer needs different skills.

Programming Model

Windows Communication Foundation has simple and easy to write/understand codes.  It has many APIs, but beside this only a small amount of these API’s is common.

There are three programming approaches in Windows Communication Foundation:

  • Imperative                 : You use programming codes in different languages to accomplish a task.
  • Configuration Based  : You use configuration files to do things.
  • Declarative                 : You use attributes to declare something.

In general, you will declare contracts and behaviors using attributes, configure endpoints, security and some other settings in configuration files and will implement service methods logic in codes.

On the other hand, you can use typed services and untyped services.  In typed services you pass normal objects and data types and/or get normal objects and data types, but in untyped services you pass and get messages to work directly with messages at a lower level.

Other useful articles

Posted in WCF | Tagged: , , | Leave a Comment »