Techmentor

Techmentor
Techmentor

Saturday, March 06, 2010

Windows Communication Foundation


There is lot of buzz going on about W* words with .NET, like WCF, WPF, WF, etc., Yes! as said in my previous post, .NET 3.5 has all these features. Let me just walkthrough what is WCF in a nutshell.

Windows Communication Foundation (WCF) is the latest service execution environment from Microsoft that enables you to seamlessly expose CLR types as services and consume services as CLR types. WCF is a unified programming model that combines the best of breed features from XML Web Services, .NET Remoting, MSMQ, and COM+ into an integrated platform that is completely based on a set of open industry standards. Because of that, WCF provides interoperability between services, and it promotes productivity, including the essential off-the-shelf plumbing required by almost any application. Here we will discuss the essential building blocks of WCF describing the concepts and architecture of WCF

WCF is a set of .NET Framework-based technologies for building and running services. WCF is the next step in the evolutionary path that started with COM, COM+, and MSMQ, and continues through .NET Remoting, ASMX, System.Messaging, and .NET Enterprise Services. WCF combines these technologies and offers a unified programming model for developing services using any CLR-compliant language. The below screenshot provides a conceptual representation of the different components that make up the WCF architecture.

As you can see from the above, the major subsystems of WCF are the Service model, the connector framework, hosting environments, and system and messaging services. The WCF service model makes service-oriented development explicit and simple from any CLR-targeted language. You use declarative attributes to mark up which aspects of their type should form the external contract of a service. The service model supports different types of contracts including service contracts, operation contracts and so on, which will be discussed later in this article. The service model also provides instance and context management for a service. WCF routes incoming messages to instances of user-defined service types. As a developer, you can leverage the declarative attributes to control how instances are associated with incoming messages as well as how the session management features of Indigo routes multiple messages to a common session object. Finally, the service model provides declarative behaviors that automate security and reliability. All of the above functionalities of service model are contained in the System.ServiceModel namespace.

Key Components of a WCF Service

A WCF service program contains four elements:

  • Contract definitions - A service must have at least one service contract, and it might contain multiple service contracts, data contracts, or message contracts
  • Endpoint definitions - One or more address-binding-contract endpoints must be declared
  • Hosting code - Some code is needed to create and start the service
  • Implementation code - The service contracts in a service need code to implement their service operations

Let us look at each of these components in detail.

Understanding Contracts

Contracts are one of the fundamental concepts in WCF. They allow clients and services to have a common understanding of available operations, data structures, and message structures while remaining loosely coupled and platform independent. WCF includes four kinds of contracts:

  • Service contract - Describes the operations a service can perform. A service contract is defined with the [ServiceContract] and [OperationContract] attributes. Binding requirements can be specified for the contract with a [BindingRequirements] attribute.
  • Data contract - Describes a data structure. A data contract is defined primarily with the [DataContract] and [DataMember] attributes.
  • Message contract - Defines what goes where in a message. A message contract is defined primarily with the [MessageContract], [MessageBodyMember], and [MessageHeader] attributes.
  • Fault contract - Allows you to document the errors that WCF code is likely to produce. A fault contract is specified along with the operation contract at the time of declaring the method. A fault contract is defined using the [FaultContract] attribute.

All four types of contracts translate between Microsoft .NET types used internally and the XML representations shared externally:

  • A service contract converts between the CLR and Web Services Description Language (WSDL)
  • A data contract converts between the CLR and XML Schema Definition (XSD)
  • A message contract converts between the CLR and Simple Object Access Protocol (SOAP)
  • A fault contract converts the CLR exceptions and to SOAP faults

You define contracts by using familiar object-oriented constructs: interfaces and classes. By decorating interfaces and classes with attributes, you create contracts.

Understanding Service Contracts

A service contract describes the operations a service can perform. A service must have at least one service contract, and it can have more than one. You can think of a service contract as follows:

  • It describes the client-callable operations (functions) exposed by the service
  • It maps the interface and methods of your service to a platform-independent description
  • It describes message exchange patterns that the service can have with another party. Some service operations might be one-way; others might require a request-reply pattern
  • It is analogous to the element in WSDL

You define a service contract by annotating an interface (or class) with the [ServiceContract] attribute. You identify service operations by placing [OperationContract] attributes on the methods of the interface. The following service contract defines only one service operation.

[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
string HelloWorld (string input);
}

Once you define a service contract using an interface, you can write a class to implement the interface. For example:

public class HelloWorldService : IHelloWorldService
{
public string HelloWorld(string input)
{
return "Hello " + input;
}
}

It is also possible for you to define the service contract directly against the implementation class and skip the interface altogether. The following class both defines and implements a service contract.

[ServiceContract]
public class HelloWorldService
{
[OperationContract]
public string HelloWorld(string input)
{
return "Hello " + input;
}
}

Although this approach works, it is not a recommended way to create services as interfaces allow you to separate the implementation from the definition of a service.

Understanding Endpoints

Services expose one or more endpoints where messages can be sent. Each endpoint consists of an address, a binding, and a contract. The address specifies where to send messages. The binding describes how to send messages. And the contract describes what the messages contain. Clients need to know this information before they can access a service. The below picture demonstrates how the components of end point play a key role in communication between a client and a service.



Services can package up endpoint descriptions to share with clients, typically by using Web Services Description Language (WSDL). Then clients can use the provided service description to generate code within their environment capable of sending and receiving the proper messages .

One of the key components of an end point is bindings, which will be the topic of focus in the next section.

Understanding Bindings

The bindings of a WCF service define how an endpoint will communicate with an external client. A binding has several characteristics, including the following:

  • Transport protocols - Some of the choices include HTTP, Named Pipes, TCP, and MSMQ.
  • Encoding - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K).
  • Security - Includes wire security (SSL) or schema-defined security (WS-Security).

Bindings can also determine if you are using sessions or a transacted communications channel. You have the choice of creating custom channels or using prebuilt bindings. WCF comes shipped with nine built-in bindings. The following table lists the WCF build-in bindings and their associated features.

BindingDescription
BasicHttpBindingBasic Web service communication. No security by default
WSHttpBindingWeb services with WS-* support. Supports transactions
WSDualHttpBindingWeb services with duplex contract and transaction support
WSFederationHttpBindingWeb services with federated security. Supports transactions
MsmqIntegrationBindingCommunication directly with MSMQ applications. Supports transactions
NetMsmqBindingCommunication between WCF applications by using queuing. Supports transactions
NetNamedPipeBindingCommunication between WCF applications on same computer. Supports duplex contracts and transactions
NetPeerTcpBindingCommunication between computers across peer-to-peer services. Supports duplex contracts
NetTcpBindingCommunication between WCF applications across computers. Supports duplex contracts and transactions

You can choose the right binding to use by mapping the features they support to your requirements.

Hosting WCF Services

As for where to put your code and what it compiles to, you have some choices. You can host your service in Internet Information Services (IIS), or you can write a small amount of extra code to host a service yourself. You can self-host a service from just about any environment that supports managed code, including a WinForms application, console application, library assembly (DLL), or Windows Service controlled through SCM (Service Control Manager). The following lists show the common hosting mechanisms for WCF services.

  • IIS (Internet Information Services) - IIS provides a number of advantages if the service uses HTTP as its transport. The nice thing about using IIS is that you don't have to write any hosting code as part of the application since IIS automatically activates service code as required. Services also benefit from IIS features such as process lifetime management and automatic restart after configuration changes. To run services using IIS, you create the service code along with its configuration file and simply save them in an IIS virtual directory.

  • WAS (Windows Activation Service) - (WAS) is the new process activation mechanism that ships with IIS 7.0. WAS builds on the existing IIS 6.0 process and hosting models, but is no longer dependent on HTTP. In addition to HTTP based communication, WCF can also use WAS to provide message-based activation over other protocols, such as TCP and named pipes. This helps WCF applications to take advantage of WAS features, such as process recycling, rapid fail protection, and the common configuration system, which were previously available only to HTTP-based applications.

  • Self-hosting - WCF services can be hosted inside any managed application, such as console applications and Windows Forms or Windows Presentation Foundation (WPF) graphical applications. To accomplish this, you need to create a class that implements a WCF service contract interface, and specify binding information in the application configuration file. The application code can then use an instance of System.ServiceModel.ServiceHost to make the service available at a particular location. To start the service, you call the ServiceHost.Open() method.

  • Managed Windows Service - A WCF service can be registered as a Windows Service, so that it is under control of the Service Control Manager (SCM). This is suitable for long-running WCF services that are hosted outside of IIS in a secure environment and are not message-activated. By hosting a WCF service with Windows Services, you take advantage of Windows service features such as automatic start at start time and control by the SCM. To host a WCF service in this way, the application must be written as a Managed Windows Service by inheriting from System.ServiceProcess.ServiceBase. It must also implement a WCF service contract interface and then create and open a ServiceHost to manage the WCF service.

A worry circulating among developers when it comes to WCF is, there seems to be not an enough documentation from microsoft on this...

ASP.NET 3.5 - An Overview

On November 19, 2007, Microsoft officially released the ASP.NET version 3.5 and Visual Studio 2008. The core assemblies installed from the .NET Framework version 2.0 are still used by the 3.0 and 3.5 versions. ASP.NET 3.5 doesn't change or take away or break any functionality, concepts, or code present in 2.0 - it simply adds new types and features and capabilities to the framework.

What's New in .NET 3.5

The .NET Framework version 3.5 includes enhancements for ASP.NET in the following areas:

  • New server controls, types, and a client-script library that work together to enable you to develop AJAX-style Web applications.

  • Extension of server-based forms authentication, roles management, and profile services as Web services that can be consumed by Web-based applications.

  • A new EntityDataSource control that exposes the Entity Data Model through the ASP.NET data source control architecture.

  • A new ListView data control that displays data and that provides a highly customizable UI.

  • A new LinqDataSource control that exposes Language-Integrated Query (LINQ) through the ASP.NET data source control architecture.

  • A new merge tool (Aspnet_merge.exe) that merges precompiled assemblies to support flexible deployment and release management. This feature is not available in Visual Web Developer Express Edition.

There are three new features worth noting in ASP.NET 3.5:

  • Integrated ASP.NET AJAX support,
  • The ListView control, and
  • The DataPager control

The .NET Framework version 3.5 is also integrated with IIS 7.0. You can now use ASP.NET services such as forms authentication and caching for all content types, not just ASP.NET Web pages (.aspx files). This is because ASP.NET and IIS 7.0 use the same request pipeline. The unified request processing pipeline means that you can use managed code to develop HTTP pipeline modules that work with all requests in IIS. In addition, IIS and ASP.NET modules and handlers now support unified configuration

AJAX Development

The .NET Framework version 3.5 enables you to create Web applications that feature next-generation user interfaces with reusable client components. The AJAX server-based and client-based programming models feature the following:

  • Server controls that support server-based AJAX development. This includes the ScriptManager, UpdatePanel, UpdateProgress, and Timer controls.

  • The Microsoft AJAX Library, which supports client-based, object-oriented development that is browser independent.

  • Server classes that enable you to develop server controls that map to custom client components whose events and properties are set declaratively.

  • Support for script globalization and localization by using client script.

  • Access to Web services and to ASP.NET authentication, roles management, and profile application services.

The .NET Framework version 3.5 enables you to easily enable asynchronous partial-page updates in a page, which avoids the overhead of full-page postbacks.


Lot more to explore with asp.net 3.5.. more to come... stay tuned...


Refreshed..

It has been a very long time since i scribbled something on my blog.. oh.. dear! are you that much busy??? come out of your gloomy world said the bear! :) where do i start now? hmm .. Since i need to do some tech mentoring i thought somewhere i should start?

Well, Being a Microsoft Techno savvy i think the best one to start with is .NET

Let me start with ASP.NET 3.5 then move with the latest ones..

Keep watching...

Sunday, December 28, 2008

MS CaseStudies for Reference

There are tons and tons of casestudies from the MS Website, here are some handpicked from various industries and verticals that really show the value and how far the technologies can go using the Microsoft Platform.

  • IT Services Company Improves Supply Chain Management with Mobility Solution
  • Aviation Company Uses PLM Suite to Improve Collaboration and Internal Operations
  • Bank Boosts User Productivity 40 Percent, Cuts Implementation Costs 50 Percent
  • Incident-Reporting Solution Provider Wins with Move to Microsoft-Based Infrastructure
  • Solution Provider Uses New Tools to Boost Productivity, Increase Time-to-Market
  • Sports Management Solution Wins the Game with New Revenue Streams, Fast Customer ROI
  • Movie Provider Automates to Meet Higher Demand, Reduce Costs, Improve Brand Visibility
  • Software Developer Creates an Affordable, Flexible Lab Information Management System
  • Nonprofit Slashes Development Cost, Adds Web Scalability, Client-Server Responsiveness
  • Medical Center Develops Patient Screening Tool Using Enhanced Web Technologies
  • Do leave a comment, in case you read these case...

    Patterns & Practices App Arch Guide 2.0 Beta 1

    Patterns & Practices App Arch Guide 2.0 Beta 1

    This guide will help solution architects and developers make the most of the Microsoft platform.  It's a distillation of many lessons learned.  It’s principle-based and pattern-oriented to provide a durable, evolvable backdrop for application architecture.  It's a collaborative effort among product team members, field, industry experts, MVPs, and customers.  Keep in mind it’s Beta so there’s still moving parts and they are processing quite a bit of feedback across the guide.

    App Arch Guide 2.0 – The Book (Beta 1) / Knowledge Base

    Key Features of the Guide

    • Canonical app frame - describes at a meta-level, the tiers and layers that an architect should consider. Each tier/layer is described in terms of its focus, function, capabilities, common design patterns and technologies.
    • App Types.  Canonical application archetypes to illustrate common application types.  Each archetype is described in terms of the target scenarios, technologies, patterns and infrastructure it contains. Each archetype will be mapped to the canonical app frame. They are illustrative of common app types and not comprehensive or definitive.
    • Arch Frame - a common set of categories for hot spots for key engineering decisions.
    • Quality Attributes - a set of qualities/abilities that shape your application architecture: performance, security, scalability, manageability, deployment, communication, etc.
    • Principles, patterns and practices - Using the frames as backdrops, the guide overlays relevant principles, patterns, and practices.
    • Technologies and capabilities - a description/overview of the Microsoft custom app dev platform and the main technologies and capabilities within it. 

    Monday, April 07, 2008

    Got Deep Breathe... Its AIR

    I took a real deep breathe when i SAW the AIR.... wow its amazing.... its really cool, its the Apple's MAC Air. An awesome notebook from Apple the Gizmo Wiz guys! Such a small notebook which weighs 1/2 of usual notebooks weight. The Core 2 Duo processor has been specially made by Intel for this notebook. Paul ottelini himself presented the chip in his hand during MAC AIR launch. The another milestone of this is the entire notebook is made of recyclable materials which is a great move in the history of notebook making towards caring the environment.  It has multifunctional touch pad which is wide enough for our fingers to play just like the iPhone image capabilities.

    Though its rocking, it has some drawbacks which we need to consider for evaluating. There are very minimal ports and notably there is only one USB port. what about up-gradation??? Time will tell us the freshness of the AIR. Take a deep breathe before you watch it!

    Watch it to believe it 
    http://www.youtube.com/watch?v=TzryoMxK7V8

    Cheers,
    Shiva

    Monday, January 07, 2008

    Managing two worlds - puh!

    Two quarters ended successfully and a New year has dawn raising hopes in dubious mind.. Really started and feeling the roller coaster ride within 6 months of my PGSEM course. I feel what it takes to be an IIM grad. Its amazing atleast for me. what a way to learn and what technology has provided for people like me who needs a so called TAG with a quality education while not in a position to come out from Job... Though am struggling to meet the ends with the blood sucking company and a mind boggling course of IIM. In one way am learning management in a very different way.

    Wish you all a very happy and prosperous new year! and hope this year bring good changes to all my friends including me! After taking up the leadership position in my company i really feel the pain of managing people.. people management is really really different. One can manage even wild animals but not the people who behave smarter than us at times. Am learning many things and i want to implement what am learning so its a nice journey which am having now and hope it sails smooth and the wind should not blow up the candle...

    Life is great! after a long time am blogging now... hope to blog more from now....

    Enjoy!

    Shiva...

    Wednesday, April 25, 2007

    A crown on my head!

    Today am really happy after getting offer of admission from IIM Bangalore for its PGSEM course. The inaguration function is on June 16th of may and this is going to be a great moment in my life as i step into one of my dream world. IIM was always my Highly reputed institution in the world and am happy to join such an wonderful institution. I thank GOD, my mom, my dad and my most encouraging person from whom i have learned a lot, Priya.

    Thanks Everyone and with almightys blessings am gonna enter a new world of MANAGEMENT

    Techmentor is going to be transformed into Managementor in couple of years...

    With Love,
    Shiva.

    Monday, August 14, 2006

    Enter the Dragon - Part I

    It was 6th August afternoon (Sunday) i reached Chennai with two bags having my dresses and certificates(though not needed) and i went to my sisters house. After that i came to my uncles house and had a nice sleep.

    Sun (not sun microsystem rather the natural sun) is so happy in chennai that it wishes everyone with great delight and i woke up in the morning with zeal enthusiasm and had my bath and lighted the lamp before god and prayed to him.

    After that i just started with my uncle in his motor bike and i was just eagerly waiting to see the building where am about to start the new assignment and which i was thinking like a turning point in my life...

    I saw the building and was eagerly waiting to enter the dragon i mean my new so called fortune 12 company VERIZON.

    END of PART I
    To be contd....

    Sunday, August 13, 2006

    New Assignment..

    On 7th August 2006, Monday I have joined Verizon in Chennai. Hope my career has a new shift..

    Friends you can always reach me at the following contact

    Email: comshiva@gmail.com
    Mobile: +91 98844 77705

    I will be meeting new people and new environment and more than anything am gonna get new friends...... This gonna be a breakthrough and hope to have a thrill of working in a fortune 12 company.

    Either it may be a wish or a comment or just pulling legs or even criticism kindly do leave it to me dear pal's .......

    loving Regards,
    Shiva.