views:

29

answers:

1

Hi,

I have an asp.net application which will always interact with wcf service to transact with the data. My question here is if the serivce is not running or some reasons got timed out. How do i need to handle the serivce exception from my consuming application.

We are using faultcontract exceptions for handling any runtime exceptions those we faced inthe service. But if the service itself is not running, how do i throw a custome message to the user saying "Service Unavailable, Please run the service".

Appreciated your help on this.

Thanks, Kiran

A: 

Assuming your service accepts http get, one option would be interrogate the service metadata from the client using something like this:

var svcUri = new Uri("http://yourhost/service.svc?wsdl");
MetadataExchangeClient mexClient = new MetadataExchangeClient(svcUri, MetadataExchangeClientMode.HttpGet);
var isHealthy = true;
try
{
   MetadataSet metadata = mexClient.GetMetadata();
}
catch (Exception ex)
{
    isHealthy = false;
} 

Another option would be to add a "heartbeat" method that returns an int or a bool to the service itself that you could periodically call from the client.

James H