【问题标题】:WCF Client Error - The request channel timed out while waiting for a replyWCF 客户端错误 - 请求通道在等待回复时超时
【发布时间】:2012-01-26 23:49:00
【问题描述】:

我有一个 Windows 服务,它在我的网络上的一台机器上托管 WCF 服务。我有一个客户端试图在网络上的另一台机器上连接到它。当我连接并尝试订阅 WCF 服务时出现以下错误:

请求通道在 00:00:09.9989999 之后等待回复时超时。增加传递给 Request 调用的超时值或增加 Binding 上的 SendTimeout 值。分配给此操作的时间可能是较长超时的一部分。

我已向客户端和服务添加跟踪以尝试找出问题,但我无法理解它。

这里是服务 app.config:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="OSAERest.api" behaviorConfiguration="MyServiceBehavior">
        <endpoint address="http://localhost:8732/api"
                  binding="webHttpBinding"
                  contract="OSAERest.IRestService"
                  behaviorConfiguration="WebHttp"/>
      </service>
      <service name="WCF.WCFService" behaviorConfiguration="WCFBehavior">
        <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WCFBinding" contract="WCF.IWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          bindingConfiguration=""
          contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="WCFBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="6553600" />
          <serviceTimeouts transactionTimeout="05:05:00" />
          <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500"
           maxConcurrentInstances="2147483647" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="WebHttp">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WCFBinding">
          <security mode="None">
          </security>
        </binding>
      </wsDualHttpBinding>

    </bindings>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "Logs\ServiceTraces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

这里是客户端 app.config:

<?xml version="1.0"?>
<configuration>
  <appSettings>

    <add key="ServiceIP" value="127.0.0.1"/>


  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IWCFService" closeTimeout="00:00:10"
          openTimeout="00:00:10" receiveTimeout="00:00:10" sendTimeout="00:00:10"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" />
          <security mode="None">
            <message clientCredentialType="Windows" negotiateServiceCredential="true" />
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/"
        binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IWCFService"
        contract="WCFService.IWCFService" name="WSDualHttpBinding_IWCFService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="traceListener"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "Logs\Traces.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

服务上的跟踪显示来自客户端的连接详细信息,因此它一定是通过了一些。此外,当我从与服务相同的机器上运行客户端时,一切正常。我可能需要做什么才能使远程连接正常工作?

【问题讨论】:

  • 如果问题确实出在客户端上,请查看您的客户端配置 - 您已将发送超时值设置为 10 秒。您是否尝试过增加超时值以查看是否可以解决问题?
  • 是的,我已将其设置为一分钟,但仍然出现相同的错误。
  • 您对问题出在客户端而不是服务上的肯定程度如何?我问是因为服务可能遇到异常或其他问题并超过超时。如果您还没有考虑的话,这只是另一种可能性。
  • 您是否尝试将超时值更改为更大的值,包括 recieveTimeout 和 sendTimeout

标签: c# .net wcf client-server


【解决方案1】:

这很可能是防火墙问题 - wsDualHttpBinding 尝试打开从服务器返回到客户端的第二个连接,这可能会被任何防火墙阻止

NetTcpBinding 对于双工通信更加健壮,正如我在博客中写的 here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-04
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多