[英]WCF: Having trouble with one-way callbacks
从WCF服务调用WPF客户端的单向回调时,我不断遇到这个令人费解的错误。
消息无法在分配的00:01:00超时内传输。 可靠频道的传输窗口中没有可用空间。 分配给此操作的时间可能是较长超时的一部分。
它不会发送太多数据,只是一个只有一个短字符串的字符串列表。
我的服务器有以下配置:
<xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RawDealService.GameService">
<endpoint address ="" binding="wsDualHttpBinding" bindingConfiguration="basicConfig" contract="MyService.IGameService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<bindings>
<wsDualHttpBinding>
<binding name="basicConfig" messageEncoding="Text">
<security mode="None"/>
</binding>
</wsDualHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
我的客户端有以下配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IGameService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
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:44259/GameService.svc" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IGameService" contract="IGameService"
name="WSDualHttpBinding_IGameService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
考虑到消息相对较小并且回调只是单向的,这可能会发生这种情况令人困惑。 我应该尝试一些不同的绑定吗?
我发现了这个问题,不幸的是,这个特殊的错误信息让我走上了一条完全错误的道路。
我的DataContract设置有一些继承的类,我没有正确标记为KnownType
。
我的猜测是在某些时候客户端试图反序列化一个相关的对象并失败了。 错误一定不是由框架优雅地处理的,也许它一直在尝试一遍又一遍地发送,并且在一分钟后没有得到响应。
也许如果我有一个双向通话,我会得到一个更丰富的堆栈跟踪。
它闻起来像一个阻塞/线程问题而不是网络问题。
您是否有任何机会阻止/等待客户端收到的单向消息? 如果是这样,并且您正在使用同步上下文,则会使WCF死锁 - 阻塞等待消息的消息队列,而在消息队列被解除阻塞之前无法接收消息。
如果是这种情况,您需要在客户端上设置UseSynchronizationContext=false
,或者在等待接收消息时避免阻塞。
也就是说,我对WsDualHttpBinding没有太多经验。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.