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

C# WCF客户端错误-请求通道在等待答复时超时,c#,.net,wcf,client-server,C#,.net,Wcf,Client Server,我有一个windows服务,它在我网络上的一台计算机上托管WCF服务。我有一个客户端正试图在网络上的另一台机器上连接到它。当我连接并尝试订阅WCF服务时,出现以下错误: 请求通道在00:00:09.999999之后等待答复时超时。增加传递给请求调用的超时值或增加绑定上的SendTimeout值。分配给此操作的时间可能是较长超时的一部分 我在客户端和服务中添加了跟踪功能,试图找出问题所在,但我无法理解 以下是服务app.config: <?xml version="1.0"?> <

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

请求通道在00:00:09.999999之后等待答复时超时。增加传递给请求调用的超时值或增加绑定上的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>
<?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>

下面是client 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>
<?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>


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

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


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

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