I have created WCF server and client applications. On the server side I need to know when the application is running.
I have created a WCF method and try to call it like this:
var myEndpoint = new EndpointAddress(url); //I generate HTTP url to endpoint here
var myBinding = new WSHttpBinding { Security = { Mode = SecurityMode.None } };
var myChannelFactory = new ChannelFactory<IMycontract>(myBinding, myEndpoint);
ISqlExpressSyncContract client = null;
try
{
client = myChannelFactory.CreateChannel();
client.IsAvailable();
((ICommunicationObject)client).Close();
return true;
}
catch (Exception)
{
if (client != null)
{
((ICommunicationObject)client).Abort();
}
return false;
}
The code works but the timeout is too long when it isn’t available. I tried using UDP discovery like provide here http://msdn.microsoft.com/en-us/magazine/ee335779.aspx. But it has the same problem when the client is not available.
What the best way to implement logic to fast ping each client and check their availability status?
Try lowering the timeout value like so:
This timeout value is for opening the communication channel. If needed, you can also tweak
SendTimeout,ReceiveTimeoutandCloseTimeout, all of them also on the binding object.