简体   繁体   中英

Ping WCF Data Service or WCF service

I investigated a bad thing, suppose we have a data service and we want to call it in consumer side such as:

 Uri dataManURI = new Uri("http://localhost:2040/DTService.svc/rest");
 DataServiceContext dataServiceContext = new DataServiceContext(dataManURI);
 var all = from ex in dataServiceContext.CreateQuery<ExternalPath_DTO>("ExternalPaths")
                                                      select ex;

after long time I will get:

Failed to load external path!, EXP:System.Data.Services.Client.DataServiceTransportException: The operation has timed out ---> System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() at System.Data.Services.Client.HttpWebRequestMessage.GetResponse() --- End of inner exception stack trace --- at System.Data.Services.Client.HttpWebRequestMessage.GetResponse() at System.Data.Services.Client.DataServiceContext.GetResponseHelper(ODataRequestMessageWrapper request, IAsyncResult asyncResult, Boolean handleWebException) at System.Data.Services.Client.QueryResult.ExecuteQuery()

or WCF service:

 AuthClient ac = new AuthClient("authEndPoint", Token);
 ac.RemoveUser(new RemoveUser_DTO_IN() { UserId = uidToDel });

so if the service is not available it is take long time to catch the exception I think if I set receivetimeout to 00:01:00 it will take 1 minute to know operation get time out.

in the other side UI be frozen until response (in my case 1 minute to get fail response).

Is these solution are useful if yes but how?

1- Define a simple operation such as Ping() and call it before any main operation ?

   AuthClient ac = new AuthClient("authEndPoint", Token);
   var watch = System.Diagnostics.Stopwatch.StartNew();
   var ping = Task.Run(() =>
   {
      ac.Ping();
   });
   try
   { 
     if (!ping.Wait(ac.Endpoint.Binding.OpenTimeout))
       {
          //Timeout on Ping for end point
           watch.Stop(); 
           return;
        }
   }
   catch (Exception exp)
    {
      watch.Stop(); 
      return;
    }

My expect is to get response within 3 seconds (open time out), in my opinion if a Ping() won't reply in 3 seconds then that service is not available.

2- telnet the service ?

Solution 1: I think solution 1 is not proper without task programming and !ping.Wait(ac.Endpoint.Binding.OpenTimeout) , because of my above explanation if service is not available then it will take 1 minute(end point receive time) to say operation get timed out.

Solution 2: how, real example?

Is there any other mechanism to know very fast that service is available or not ?

any help would be truly appreciated.

Have you tried to Warm-up your IIS pool initialization ?

A common problem faced by website administrators is the need to perform initialization tasks and "warm up" tasks for a web application. Larger and more complex web applications may need to perform lengthy startup processing, prime in-memory caches, generate content, etc... prior to serving the first HTTP request.

The IIS 8.0 Application Initialization feature enables website administrators to configure IIS 8.0 to proactively perform initialization tasks for one or more web applications.

I've been facing similar problems - but not that much (1min+). Generally IIS take some seconds (10~20 sec) to initilize, so manipulating recycle interval (default 1740 min) and idle timeout (default 20 min) may improve your service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM