WCF 客户端错误 - 请求通道在等待回复时超时

问题描述 投票:0回答:1

我有一个 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>

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

c# .net wcf client-server
1个回答
0
投票

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

NetTcpBinding 对于双工通信来说更加稳健,正如我在博客这里

所写的那样
© www.soinside.com 2019 - 2024. All rights reserved.