20 October 2012

REST services

Sometimes SOAP might actually be overkilled for particular web service scenarios. In many cases the developer may need high range of interoperability. So, in order to increase interoperability, they have to restrict themselfs to basic XML message that they transmit over HTTP and they can take advantage of advance WS* specifications that are part of these protocols.

For security, they simply use HTTPS that provides facility of SSL for all the security needs.This is most common today. Most of the developer are using SOAP without WS* and this is often referred to as simple SOAP. Main benefit of doing this is it increases interoperability. Also, there is large number of tool support for generating clients & services from WSDL definition. We can take WSDL schema definition and automatically generate the code that we need without our framework and that code will hide all the underlying XML & HTTP details. This is why, most of the developer still use SOAP.

Some developer decide that they really don't need SOAP at all & just want to exchange XML messages over HTTP without SOAP framing element. This is often referred as plain-old XML (POX). This is usually used in combination with HTTP. When you take this approach, the interoperability is virtually guaranteed because you can easily find HTTP & XML stack on any platform in demand today. But it does require some direct XML / HTML coding.

In order to use POX, you should be comfortable writing XML based code using various XML APIs to produce & consume messages and you also need to be comfortable with HTTP stack for programming the logic to send & receive messages.

POX applications can also be defined in a REST-ful way. If you design your services around HTTP and if you are adhered to restful design principals and you define all your actions in terms of HTTP method & verbs, then indeed you are going to use what we call as RESTful architecture that happens to use plain-old XML messages over wire. 

02 October 2012

WCF - Handling Exceptions

There may be many different kinds of exceptions that may occur at the client side. But client channels need to be prepared for two main exception types :

1. Communication Exceptions - This is a base class that represent various runtime communication errors. This exception is a generalize exception to catch any type of communication exception that is thrown by your service operation also known as Fault Exception. They typically represent business oriented exceptions.

2. Timeout Exception - It is not delivered from communication exception. This represents the error that occurs when send timeout limit exceeded. So when you are writing your client side communication logic, you need to take it into account these various types of exceptions that can occur. Remember that after certain exceptions, the client side channel may enter into "faulted" state which will require you to call abort on the channel instead of close.


To Catch Communication Exception :

catch(CommunicationException ce)
{
       client.Abort();
}

To Catch Timeout Exception :
catch(TimeoutException te)
{
       client.Abort();
}

Configure Client Channel - through Binding & Behaviors

You can configure client channel through both binding & behaviors applied to client scenario. The binding configures the wire level protocol detail, whereas , the behavior configures local execution environment.

Key things that you might configure on the client side binding :-

1. Send Timeout Value : this influence when the time out exception happens.
2. Transport Protocol specific setting : that usually has to be sync with service setting as well.

There are also some client side behavior that you can apply to your client side endpoints. That's why they are called client side endpoint behavior in WCF.

I. Configure client side binding :-

II. Configure client side behavior :-