简体   繁体   English

Ping WCF数据服务或WCF服务

[英]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() 无法加载外部路径!,EXP:System.Data.Services.Client.DataServiceTransportException:操作已超时---> System.Net.WebException:操作已在System.Net.HttpWebRequest.GetResponse()处于超时时间System.Data.Services.Client.HttpWebRequestMessage.GetResponse()---内部异常堆栈跟踪的结束---在System.Data.Services.Client.DataServiceContext的System.Data.Services.Client.HttpWebRequestMessage.GetResponse()处。 System.Data.Services.Client.QueryResult.ExecuteQuery()中的GetResponseHelper(ODataRequestMessageWrapper请求,IAsyncResult asyncResult,Boolean handleWebException)

or WCF service: 或WCF服务:

 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. 因此,如果服务不可用,则需要很长时间才能捕获异常,我认为如果将receivetimeout设置为00:01:00 ,则需要1分钟才能知道操作是否超时。

in the other side UI be frozen until response (in my case 1 minute to get fail response). 在另一侧UI 被冻结直到响应(在我的情况下1分钟得到失败响应)。

Is these solution are useful if yes but how? 如果是,这些解决方案是否有用,但如何?

1- Define a simple operation such as Ping() and call it before any main operation ? 1-定义一个简单的操作,如Ping() ,并在任何主操作之前调用它?

   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. 我的期望是在3秒内(开放时间)得到响应,在我看来,如果Ping()不会在3秒内回复,那么该服务不可用。

2- telnet the service ? 2- telnet服务?

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. 解决方案1:我认为解决方案1不适合没有任务编程和!ping.Wait(ac.Endpoint.Binding.OpenTimeout) ,因为我的上述解释如果服务不可用则需要1分钟(终点接收时间)说操作得到超时。

Solution 2: how, real example? 解决方案2:如何,真实的例子?

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 ? 您是否尝试过预热IIS池初始化

A common problem faced by website administrators is the need to perform initialization tasks and "warm up" tasks for a web application. 网站管理员面临的一个常见问题是需要为Web应用程序执行初始化任务和“预热”任务。 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. 更大和更复杂的Web应用程序可能需要在提供第一个HTTP请求之前执行冗长的启动处理,主要内存缓存,生成内容等。

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. IIS 8.0应用程序初始化功能使网站管理员能够配置IIS 8.0以主动执行一个或多个Web应用程序的初始化任务。

I've been facing similar problems - but not that much (1min+). 我一直面临类似的问题 - 但不是那么多(1分钟+)。 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. IIS通常需要几秒钟(10~20秒)来启动,因此操作循环间隔(默认为1740分钟)和空闲超时(默认为20分钟)可能会改善您的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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