Labels

Monday, June 20, 2011

Windows Communication Foundation

Windows Communication Foundation (WCF) is designed for Service Oriented Architecture

WCF’s most important aspects:
  • Unification of the original .NET Framework communication technologies
  • Interoperability with applications built on other technologies
  • Explicit support for service-oriented development.
 Existing Communication:
  • ASMX, also called ASP.NET Web Services, would be an option for communicating with the Java to achieve cross-vendor interoperability.
  • .NET Remoting is a natural choice for .NET-to-.NET communication
  • Distributed Transactions
  • Web Services Enhancements (WSE) might be used along with ASMX to communicate with the Java EE-based reservation application and with the partner applications.
  • System.Messaging, which provides a programming interface to Microsoft Message Queuing (MSMQ), could be used to communicate with Windows-based partner applications that weren’t always available. The persistent queuing that MSMQ provides is typically the best solution for intermittently connected applications.
  •  System.Net might be used to communicate with partner applications or perhaps in other ways. Representational State Transfer (REST)
using System.ServiceModel;

[ServiceContract]
class RentalReservations
{
   [OperationContract]
   public bool Check(int vehicleClass, int location, string dates)
   {
      bool availability;
      // code to check availability goes here
      return availability;
   }

  public int GetStats()
  {
    int numberOfReservations;
    // code to get the current reservation count goes here
    return numberOfReservations;
  }
}
Using explicit interfaces like this is slightly more complicated, but it allows more flexibility. For example, a class can implement more than one interface, which means that it can also implement more than one service contract.

using System.ServiceModel;

[ServiceContract]
interface IReservations
{
   [OperationContract]
   bool Check(int vehicleClass, int location, string dates);
}

class RentalReservations : IReservations
{
   public bool Check(int vehicleClass, int location, string dates)
   {
     bool availability;
     // logic to check availability goes here
     return availability;
   }

   public int GetStats()
   {
     int numberOfReservations;
     // logic to determine reservation count goes here
     return numberOfReservations;
   }
}

using System.Runtime.Serialization;
[DataContract]
struct ReservationInfo {
   [DataMember] public int vehicleClass;
   [DataMember] public int location;
   [DataMember] public string dates;
}

Hosting a Service Using IIS or WAS
reserve.svc
<%@Service language=c# class="RentalReservations" %>

  • IIS-hosted WCF services can only be accessed using SOAP over HTTP. No other transport protocols are supported.
  • Although WAS doesn’t require a Web server to be installed on the system, WCF services hosted in IIS obviously do.
Hosting a Service in an Arbitrary Process


Defining Endpoints

  • An address indicating where this endpoint can be found. Addresses are URLs that identify a machine and a particular endpoint on that machine.
  • A binding determining how this endpoint can be accessed. The binding determines what protocol combination can be used to access this endpoint along with other things, such as whether the communication is reliable and what security mechanisms can be used.
  • A contract name indicating which service contract this WCF service class exposes via this endpoint. A class marked with ServiceContract that implements no explicit interfaces, such as RentalReservations in the first example shown earlier, can expose only one service contract. In this case, all its endpoints will expose the same contract. If a class explicitly implements two or more interfaces marked with ServiceContract, however, different endpoints can expose different contracts, each defined by a different interface.

Creating a WCF Client

 Creating a proxy requires knowing what contract is exposed by the target endpoint, and then using the contract’s definition to generate the proxy. In WCF, this process can be performed using either Visual Studio or the command-line svcutil tool.


 Windows Communication Foundation

Workflow in the .NET Framework 4

Goal
creating unified application logic
creating scalable applications with simple state management.
 Advantage
One obvious advantage of this approach is that the workflow doesn’t hang around in memory blocking a thread and using up a process while it’s waiting for input.
Another advantage is that a persisted workflow can potentially be re-loaded on a machine other than the one it was originally running on. Because of this, different parts of the workflow might end up running on different systems.
other advantages: It can make coordinating parallel work easier, providing automatic tracking of the workflow’s execution is straightforward. the main control flow of a workflow can be assembled graphically.

Overview
Base Activity Library (BAL), custom activities

Custom activities can be written directly in code, using C# or Visual Basic or another language. They can also be created by combining existing activities, which allows some interesting options. For example, it might be possible for less technical people to create WF applications using these pre-packaged chunks of custom functionality.

A workflow's state and control flow are typically described in eXtensible Application Markup Language (XAML), while custom activities can be written in code.

Workflow in the .NET Framework 4, it's not compatible with earlier version in 3.5
  • Sequence: Executes activities in sequence, one after another. The sequence can contain If activities, While activities, and other kinds of control flow. It’s not possible to go backwards, however—execution must always move forward.
  • Flowchart: Executes activities one after another, like a Sequence, but also allows control to return to an earlier step. This more flexible approach, new in the .NET Framework 4 release of WF, is closer both to how real processes work and to the way most of us think. 
 A workflow service uses WCF to expose WF-based logic
  • Implementing services that do parallel work is straightforward: just drop activities into a Parallel activity.
  • Tracking is provided by the runtime.
  • Depending on the problem domain, it might be possible to create reusable custom activities for use in other services.
  • The workflow can be created graphically, with the process logic directly visible in the WF workflow designer.
Where to run
WF workflows can run in pretty much any process. You’re free to create your own host, even replacing some of WF’s basic services (like persistence) if you’d like.
A simpler option is to host a WF workflow in a worker process provided by Internet Information Server (IIS). While this works, it provides only a bare-bones solution. Microsoft is providing a technology code-named “Dublin”. Implemented as extensions to IIS and the Windows Process Activation Service (WAS), a primary goal of “Dublin” is to make IIS and WAS more attractive as a host for workflow services.

Microsoft Windows Workflow Foundation