服务只能在特定时间之间访问

本文关键字:定时间 之间 访问 服务 | 更新日期: 2023-09-27 18:22:14

我需要创建一个WCF服务,从数据库中获取一些数据。出于某种原因,这项服务只能在晚上使用。web.config中的一些代码告诉我这应该是可能的,但我不知道怎么做。

服务只能在特定时间之间访问

不确定是否有办法在web.config中定义,但似乎可以使用PowerShell来调度和终止服务。MSDN关于安排后台作业的博客文章

这在web.config中是不可能的。这是一个非常不寻常的要求。当然不是内置的。

就像这样:

if (DateTime.Now.Hour >= 22)
  throw new FaultException("ServiceUnavailable");

对于客户端,您需要调整绑定元素的sendTimeout属性。对于服务,您可能希望调整绑定element的receiveTimeout属性。

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="longTimeoutBinding"
        receiveTimeout="00:10:00" sendTimeout="00:10:00">
        <security mode="None"/>
      </binding>
    </netTcpBinding>
  </bindings>
  <services>
    <service name="longTimeoutService"
      behaviorConfiguration="longTimeoutBehavior">
      <endpoint address="net.tcp://localhost/longtimeout/"
        binding="netTcpBinding" bindingConfiguration="longTimeoutBinding" />
    </service>

如果这能回答你的问题,请告诉我。