Wednesday, July 27, 2005

The behaviors of Indigo.

Or should I say the behaviors of Windows Communication Foundation. Cause that is the official name now for Indigo.
It's been a while since I wrote my last article, but I promised a follow up in the piece about contracts in Indigo so here we go.
Most things in indigo are about outside communication. But there are also parts of Indigo that do there work internally. These things control the behavior of the service, hence the name Behaviors :-)
In Indigo you can specify 2 types of behaviors. The first attribute controls the service as a whole. This attribute is called ServiceBehavior. It has for example a property called ConcurrencyMode, this can be used to control concurrent access to the service.
The second behavior attribute controls the behavior of a method. A method implements an operation hence the name of the attribute OperationBehavior.
It can controle the impersonation, the transaction handling and other things. We will go into the transactions a bit deeper.
Transactions is a verry important part of Indigo. And, as said, one way is to controlle the transactional requirements thru the OperationBehavior of methods.
An example:
using System.ServiceModel;
[ServiceContract]
class XactOperations
{
   [OperationContract]
   public int Add(int value1, int value2)
   {
      return value1 + value2;
   }

   [OperationContract]
   [OperationBehavior(RequireTransaction=true,    AutoCompleteTransaction=true)]
   int Update(int value1, int value2)
   {
      // Insert value1 and value2 into
      // two different databases
   }
}

In this example the behavior attribute stipulates that this operation requires a transaction and that it should use autocomplete.
If we call this method from a client that is not using a transaction the method will run inside it's own transaction. But what is we want to use a transaction that is already started? Well then we need to specify that our component can receive a transaction context. This is accomplished by adding the TransactionFlowAllowed property to the OperationContract. See my article about contracts for some more info in contracts in general.
Transaction support is not limited to the indigo platform. It will support transactions as long as the other system implements the WS-AtomicTransaction specification.
As you can see, playing with these attributes is powerful and easy. No coding mumbo-jumbo, just attributes. Can it get any easier?
The more I read about it the more eager I am to write an example app that uses indigo. Maybe for a next article? :-)

0 Comments:

Post a Comment

<< Home