views:

89

answers:

3

What is the best way to confirm that these consumed services are actually up and running before I actually try to invoke its operation contracts? I want to do this so that I can gracefully display some message to the customer to give him/her a more pleasant user experience. Thanks.

+1  A: 

I wouldn't consider myself a part of the SO Community but I have been in this situation before and it was simple exception handling around the service calls. If you're in control of the services, than you can put up a status method that returns it's current state. If the network is down and you can't even hit the service than you'll have to handle that with some exception handling but you could get a status back if the parent service is unable to use it's child services.

If you're following SO though, my own opinion here, you shouldn't be concerned with the consumed service consuming other services.

Joshua Belden
SO == StackOverflow, no?
Dennis Palmer
Dennis: Yes, you're right on.
marc_s
SO == Service Orientation
Joshua Belden
+2  A: 

I created an IsAvailable method that checked all of my underlying dependencies for my service. My client would call this method before doing anything else with my service. If it returned true, my service was available for use.

We also put intermediaten checks to rollback any changes if one of the underlying dependencies was not able at the time of the transaction.

Example:

Here is a simple example of how my IsAvailable is used by the client:

IsAvailable code

[WebMethod]
public bool IsAvailable()
{
    bool EverythingUpAndRunning = true;

    try
    {
        string TestConnectionString = WebConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
        SqlConnection sqlConnection = new SqlConnection(TestConnectionString);
        sqlConnection.Open();
        sqlConnection.Close();
        sqlConnection.Dispose();
    }
    catch(Exception ex)
    {
        EverythingUpAndRunning = false;
    }

    return EverythingUpAndRunning;
}

The client code:

MyWebService proxy = new MyWebService();
if(proxy.IsAvailable)
{
    //if true, you can use the other available methods in the service
}
Michael Kniskern
Service clients would still need to catch exceptions on each service call including the IsAvailable method.
Dennis Palmer
It would retrun a false if the service is not available. I do not throw an exception. Forgot to mention that.
Michael Kniskern
Interesting approach. It seems like you could potentially apply this in a way that was messaging-protocol agnostic.
Paul Morie
Could you give a micro-example of this, please?
Paul Morie
@Paul Morie - I have updated my answer in response to your comment
Michael Kniskern
A: 

here is a good post try to explain how to consume rest based services i hope help u

http://blog.flair-systems.com/2010/05/how-to-consume-rest-based-services.html

Waleed Mohamed