返回的消息很大时,WCF调用超时

时间:2013-05-14 12:07:54

标签: wcf wcf-binding

我们有一个系统,客户端Flash应用程序正在调用基于asmx的搜索Web服务,该服务又使用NetTcpBinding调用Windows服务中托管的wcf服务。当没有时,这工作正常。搜索结果很小。但是当搜索结果变大时,在2000条记录的范围内,我们在asmx服务中得到一个异常,它调用wcf:

`The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.`

为了解决错误,我们启用了服务跟踪,发现报告的错误是:

`The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:01:00'.` 

我们已经增加了服务器和客户端配置中的超时值,并且还增加了maxItemsInObjectGraph值。 wcf调用没有发生错误,因为我们可以调试它,观察到的行为是,当wcf调用返回时,asmx服务中的代码正在命中异常块并报告上述错误。

服务器端配置:

<system.serviceModel>
<services>
  <service name="***.SearchController" behaviorConfiguration="serviceBehavior">
    <endpoint address="net.tcp://localhost:8228/SearchController" binding="netTcpBinding" contract="***.ISearch" name="SearchController" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceDebug includeExceptionDetailInFaults="True" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <netTcpBinding>
    <binding name="LargeMessageBinding"
             maxBufferPoolSize="2147483647"
             maxBufferSize="2147483647"
             maxConnections="2147483647"
             maxReceivedMessageSize="2147483647"
             portSharingEnabled="false"
             transactionFlow="false"
             listenBacklog="2147483647"
             closeTimeout="infinite" 
             openTimeout="infinite" 
             receiveTimeout="infinite" 
             sendTimeout="infinite">
      <security mode="None">
        <message clientCredentialType="None"/>
        <transport protectionLevel="None" clientCredentialType="None"/>
      </security>
      <reliableSession enabled="false"/>
      <readerQuotas maxDepth="2147483647"
         maxStringContentLength="2147483647"
         maxArrayLength="2147483647"
         maxBytesPerRead="2147483647"
         maxNameTableCharCount="2147483647" />
    </binding>
  </netTcpBinding>
</bindings>
<diagnostics wmiProviderEnabled="true">
  <messageLogging
         logEntireMessage="true"
         logMalformedMessages="true"
         logMessagesAtServiceLevel="true"
         logMessagesAtTransportLevel="true"
         maxMessagesToLog="3000"
   />
</diagnostics>
<client></client>

客户端(axms)Side Config:

<system.serviceModel>
    <client>
  <endpoint address="net.tcp://localhost:8228/SearchController" binding="netTcpBinding" behaviorConfiguration="endpointBehavior" contract="***.ISearch" name="NewSearch"/>
</client>
    <bindings>
  <netTcpBinding>
    <binding name="LargeMessageBinding"
             maxBufferPoolSize="2147483647"
             maxBufferSize="2147483647"
             maxConnections="2147483647"
             maxReceivedMessageSize="2147483647"
             portSharingEnabled="false"
             transactionFlow="false"
             listenBacklog="2147483647"
             closeTimeout="infinite"
             openTimeout="infinite"
             receiveTimeout="infinite"
             sendTimeout="infinite">
      <security mode="None">
        <message clientCredentialType="None"/>
        <transport protectionLevel="None" clientCredentialType="None"/>
      </security>
      <reliableSession enabled="false"/>
      <readerQuotas maxDepth="2147483647"
         maxStringContentLength="2147483647"
         maxArrayLength="2147483647"
         maxBytesPerRead="2147483647"
         maxNameTableCharCount="2147483647" />
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="endpointBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>

用于从asmx服务调用wcf的代码:

List<***.SearchResult> results;
    using (var searchFactory = new ChannelFactory<***.ISearch>("NewSearch"))
    {
        Legacy.ISearch searchProxy = searchFactory.CreateChannel();
        results = searchProxy.Search(searchOption);
    }

此调用正在报告异常。

我们不确定为什么即使增加配置中的阈值也会出现超时问题。可能是服务没有拿起我们的绑定配置并使用一些默认配置值,因此抛出错误。不确定验证服务是否在运行时实际获取配置的方法是什么。 需要帮助来解决此问题。

1 个答案:

答案 0 :(得分:2)

您必须在应用程序中使用绑定,但只能声明它,使用bindingConfiguration属性

<endpoint address="net.tcp://localhost:8228/SearchController" binding="netTcpBinding" contract="***.ISearch" name="SearchController" bindingConfiguration="LargeMessageBinding" />

bindingConfiguration="LargeMessageBinding"也是客户端配置