WCF 服务超时 - 服务需要几分钟才能响应简单请求

WCF Service Timeout - Service Takes Minutes to respond to simple request

我们有一个简单的服务配置如下:

<configuration>
  <connectionStrings>
    <add name="CONN" connectionString="Server=MYSERVER,1433;Database=mydb;User Id=user;Password=pass;"/>
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="MyNamespace.MyService">
        <host>
          <baseAddresses>
            <add baseAddress="https://mywebsite.com/TestService/"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="MyNameSpace.IMyService" bindingConfiguration="defaultBinding" bindingNamespace="MyNameSpace"/>
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="defaultBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647"
    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

在我向绑定名称添加附加参数之前服务超时="defaultBinding"(closeTimeout、openTimeout、receiveTimeout、sendTimeout、maxbuffersize、maxreceivedmessagesize)。

我们的服务器只启用了 TLS1.2。 该服务托管在 IIS 中,证书似乎没问题 - 在 Web 中浏览 WSDL 看起来没问题。

在托管服务的同一台机器上使用 SOAPUI 超时(我想这真的很快?)

是否有我不知道的 Web 配置设置,或者这是否取决于服务器计算机或可能是 IIS?

请求可能需要几分钟才能完成 - 即使是像 GetVersion() 调用这样的简单请求,也只是 returns 一个字符串。我们甚至重新启动了机器、IIS 等,并尝试了新的请求 - 同样的问题。

原来我的 GetVersion() 调用实际上有一个 LogActivity() 调用,它会记录到数据库。 web.config 中的连接字符串不正确导致数据库连接旋转,直到数据库连接超时。数据库连接超时设置为高于 service/client 的超时,因此客户端会在数据库超时发生之前超时。数据库连接超时静默发生,因为我们不需要记录失败的日志记录尝试。

修复连接字符串后服务响应迅速。

故事的寓意:仔细检查您的功能 - 即使它们看起来很简单,但它们可能在幕后做一些其他事情:)