我们有一个系统,其中客户端 Flash 应用程序正在调用基于 asmx 的搜索 Web 服务,该 Web 服务又使用 NetTcpBinding 调用托管在 Windows 服务中的 wcf 服务。这在没有时工作正常。的搜索结果很小。但是当搜索结果变大时,在 2000 条记录的范围内,我们在调用 wcf 的 asmx 服务中遇到异常:
`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)端配置:
<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);
}
此调用正在报告异常。
即使在配置中增加阈值后,我们也不确定为什么会出现超时问题。可能是该服务没有获取我们的绑定配置并使用一些默认配置值,因此引发了错误。不确定服务是否在运行时实际获取了我们的配置的验证方法是什么。在解决此问题时需要帮助。