Wednesday, April 28, 2010

SilverLight 4.0 –Overriding Anonymous Style.

 

In my pervious Blog post I showed how define Anonymous style for the Button control. what if we wanted to override that one. Here is how we need to do to override the default style. 

We need to set the Style attribute using this code  Style=”{x:Null}” ( Please see the button Good One)

image
image

Nandri(Thanks)

SreenivasaRagavan.

SilverLight 4.0 – Default Style

 

In Silverlight 4 Now we have option to set Default style to particular type of control . for example let say I have 4 button controls in my Silverlight UI. I wanted to define Style for the following properties  Margin, Width and height. here is how we usually define Style in Silverlight 3.0.

image

but in Silverlight 4.0 we no need to specify Name. Just remove the Name attribute from Style as shown below.

image

by removing the Name Attribute we are defining Anonymous  style this Style applies to all the button on our application this makes our XAML Code looks tidy and nice

imageimage

Nandri(Thanks)

SreenivasaRagavan

Thursday, April 22, 2010

SilverLight 4.0 Training Material

 

The Silverlight 4 Training Course includes a whitepaper explaining all of the new Silverlight 4 features, several hands-on-labs that explain the features, and a 8 unit course for building business applications with Silverlight 4. please click to download from the following URL.

image

http://www.microsoft.com/downloads/details.aspx?FamilyID=24CEA29E-042E-41C9-AA16-684A0CA5F5DB&displaylang=en

Nandri(Thanks)

SreenivasaRagavan

Thursday, April 15, 2010

WCF 4.0 Routing Service –Content Based Routing (CBR).

What is Content Based Routing?

Content-Based Routing seeks to route messages. Messages are routed  not by a specified destination, but by the actual content of the message itself. In a typical application, a message is routed by being opened and then having a set of rules applied to its content.
In this blog post I am going to show how to configure WCF 4.0 Routing Service as Content based router. Here I am going to take an example scenario is Worker Timesheet submission. The timesheets are submitted to one of two services, once service is responsible for processing employees only timesheets and other service will process Contractors Timesheet. The reason two different services are required is that  employee timesheets are automatically processed and approved but contractors timesheets require human interaction to validate the timesheets before their approval.
image
Another thing is that  we do not want the client to know that there are two separate services to handle this timesheets and further to this we do not want them to be responsible for picking which service to call and send the timesheet to.

Here is my VS.NET  project structure to implement this above scenario in WCF 4.0 using Routing Service.

image

now let’s create each service component.

Timesheet Service contract definition

 image

Now we need to implement the above contract in two different services  EmployeeTimeSheetSvc and ContractorTimeSheetSvc. for the demo purpose we simply write out the Timesheet details to the console window.

EmployeeTimeSheetSvc [Hosting]

 image

      EmployeeTimeSheet service listening at the following http://localhost:8000/EmployeeService" endpoint with basicHttpBinding. here we are hosting EmployeeTimeSheetSvc    service in Windows console application [ for real world we should be hosting it in IIS /WAS]

image

ContractorTimeSheetSvc [Hosting]

      image

  ContractTimeSheet service listening  at the following http://localhost:8001/ContractorService" endpoint with basicHttpBinding.


image

 

Router Service [Hosting]

First we need to add the following two .NET Assembly to the Routing Service project.

image

     Here we are hosting RoutingService class.

image

       Here the  RoutingService implements the System.ServiceModel.Routing.IRequestReplyRouter contract. There are other contracts that you could use  based your service requirements .

image

image

 

If you look at the above configuration the  routing section specifies two filters which uses  XPath to perform the routing. These filters are used in the filterable section which specifies that when the filter’s condition are matched which endpoint should be called. In this  example  we are checking if the  employee type is PERM then  the “empEP” endpoint is called and if the employee type is CONTRACTOR then  “conEP” endpoint is called.

WCF Client Application

Here we are  invoking Timesheet service using ChannelFactory class. This allows us to call WCF service without adding a Service reference[using VE.NET IDE] . but we need to Reference the  Service Contract interface though [ We can  simply copy the service contract Interface definition  to this project.]

image

image

So using WCF 4.0 Routing service it is very easy to configure Router service to forward a message on to another WCF service based on the content of the received message.

Nandri(Thanks)

SreenivasaRagavan

Wednesday, April 14, 2010

WCF 4.0 Routing Service –Failover

In this blog post I am going to show how to configure  WCF 4.0 Routing Service Failover option. I wanted to make sure not to confuse Failover Vs Load balancing.  Service Failover means when client can not reach or communicate with the Service the fall back route is called Failover. for example let say we have  hosted a WCF order Service as main Service, when client wanted to place an order it calls  PlaceOrder Operation  service once service receives the message it will process it.

suppose let say when client calls Operation (Method) on order service at that time if service not available in this case the PlaceOrder Operation message dropped between server and client instead of losing a message we will persist in MSMQ once service comes online we can push these order again to the service to process.

In Windows environment Microsoft Messaging Queue (MSMQ) Service mainly used for to build fault tolerance applications. MSMQ provides Public (as a Active Directory ) and Private Queues to persist the messages when client fails to communicate with service. Here we are going to use MSMQ Private Queue as a our backup service.

image

Now we need to create and host the following Service components.

  1. Define Service Contract and Implementation.
  2. WCF Order Service (Main service)
  3. Backup or Fail over Service
  4. Routing Service
  5. Client App

1) Service & Operation Contracts Definition:


image 

2) Order Service Hosting (Main Service)

image

Configuration

image

3) Backup or Failover Service Hosting

image[44]


image

4) Routing Service Hosting

image

image

     

Client Application

Create Windows console application and add Service Reference ( Order Service) .

image

     Now we need to modify the Endpoints which points to Router service instead of pointing to WCF Order Service.

Before Modification

image

    After Modification

image

image

        when main service is not running then Router service will send message to MSMQ .

 
image


Nandri(Thanks)

SreenivasaRagavan

Tuesday, April 13, 2010

WCF 4.0 Routing Service –Multicasting

What is Multicasting?

Multicasting is a communication process that takes place in a network environment. Essentially, a multicast is a message that originates with a single user and is received by multiple end points around the network.

In this blog post I am going to show WCF Routing Service Multicasting.  Here a WCF Client sends a message to routing service that will Route the same message to one or more  WCF Services which is hosted in different bindings and Addresses .For the demo purpose I am going to create Two WCF services( namely one ,two) and self hosting as windows Console application.

image

When we creating Multicast Service the WCF Operation Contract should be defined as One-way. Here is the definition of WCF Service contract which I am going to use here. 

   WCF Service Contract:

image

      Here are the WCF services ,Routing Service and their endpoints definitions.

image

 

WCF Service Implementation:

image
    

          This WCF service listen on port 6001 and binding netTcpBidning.

WCF Service Configuration definitions:

    image

        Create Second WCF service and implementation the same  service contract  with port 6002 and binding as  wsHttpBinding.

        Now we need to create WCF Routing Service and define the configuration.

Routing Service & Configuration:

image

Here I am using the “ISimplexDatagramRouter” as the contract’s interface and it is a simple message router, with a datagram, one-way, semantics and no session support (you can use “ISimplexSessionRouter” for session support, and use “IRequestReplyRouter” for a request/replay routing scenario).

 

image

By default this Routing Service routes the message to all the destination services is recognizes via the routing configuration (see below). This is done because I am using the “MatchAll  message filter.  Here is the list of  message filters that come OOTB with WCF.

image

image

WCF Client:

  image

     To test   First Start WCF service 1 & 2 then Routing service  finally run the client.

image

The Routing service also has the options to define and use a Failover  or backup service. In the case of failure to deliver the message to any of the destination service endpoints. In the next blog we will see how to configure failover options. 

Nandri(Thanks)

SreenivasaRagavan

WCF 4.0 Routing Service – Protocol Bridging

Today Microsoft Released VS.NET 2010 and .NET 4.0 this release also includes WCF 4.0 .  In this release WCF 4.0 has many new features like

  • Simple Configuration
  • Router Service
  • Serialization Enhancements
  • Web Programming
  • Service Discovery
  • Workflow Service.

In this blog post We are going to look at  WCF 4.o Routing Service- Protocol bridging. 

Protocol Bridging is basically transport conversion. for example the below picture shows that the client sends a message to  Routing Service via HTTP protocol once message reaches to Routing Service now routing service will route the same message to backend WCF Service via  TCP/IP protocol. Here we are bridging the protocols between  HTTP and TCP/IP.

image  

For the demo purpose I am going to Create WCF service  and self hosting in Console application.

Now We need to create and host the following Services and client.

  1. WCF Service
  2. Routing Service
  3. WCF Client
  4. Test it

 

1) Creating WCF Service

Fire up VS.NET 2010 make sure that you have selected .NET Framework 4.0 and then select Console application project template  to create a new project name the project as SystemWCFService.

image

Now we need to add the imageAssembly References to the project. 

ServiceContract and operation contract definition

Here I am define three operations contracts .  GetProcess operations will select all process currently running on the server and returns to client.

image

  Service Implementation
image

Service Hosting

image

Service Configuration
image

 

[Note : In WCF 4.0 we can create a service with Simple configuration and we can use protocol mapping to override default endpoints]

 

2) Creating Routing Service

To create Routing service we need to add new console project[.NET Framework 4.0]  and add the following Assembly References to it.

image

Now we need to host our routing service for that we need  ABC  A- Address , B-Binding , C-Contract .   WCF 4.0 comes with the following Routing services Contracts . ISimplexDatagramRouter, ISimplexSessionRouter, IRequestReplyRouter, IDuplexSessionRouter our WCF service message  pattern is Request-Reply so we are going to host our Routing service with IRequestReplyRouter contract.

image

image

Define  FilterTable and Filters .

Now we need to Add the routing table and message filters. These are the settings used by the router service to do the actual routing of the messages

image

 

Now we need to define actual Service Endpoint inside Routing Service configuration file .

image

Here we need to specify  actual WCF service Endpoint and binding. actually routing service do not care about service contract that is why we put  *.

Hosting Routing Service


image

Routing Service listens an Endpoint which client expects.  [i.e http://localhost:9000/SystemRoutingService]

3) Creating WCF client & calling WCF Service

Here we are going to use ChannelFactroy class to create WCF proxy and invoke the Operations. for that we need  WCF Service binding , Endpoint & Contract.

Here Endpoint Address same as Routing Service EP.

image

Testing:

First execute the  WCF service and then Routing Service now run the client . Now  client calls GetProcess  method and receives  result from Actual WCF service via Routing service .

image

Next Blog post I will show how Routing service  Multicasting works.

Nandri(Thanks)

SreenivasaRagavan