WCF:单向回调出现问题

7

当我从一个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>

考虑到消息相对较小且回调仅单向,这种情况实在令人困惑。我应该尝试使用一些不同的绑定吗?


你能否发布你的服务接口类(也称回调接口)? - Rev
@Rev 请看下面。我找到了问题,但是直到明天才能接受自己的答案。无论如何,谢谢! - Ben
2个回答

6
我找到了问题,不幸的是,这个特定的错误消息让我走上了完全错误的道路。
我的DataContract设置中有一些带继承的类,而我没有正确地标记KnownType
我猜想,在某个时候,客户端尝试对一个关联对象进行反序列化并失败了。该框架可能没有优雅地处理该错误,并且可能会一直尝试发送请求,并在一分钟后没有得到响应。
也许如果我有一个双向呼叫,我会得到一个更详细的堆栈跟踪。

4

这似乎是一个阻塞/线程问题,而不是网络问题。

你是否有任何形式的阻塞/等待客户端接收单向消息?如果是这样,并且你正在使用同步上下文,那么你会死锁WCF - 阻塞消息队列等待消息,而消息只能在消息队列被解除阻塞后才能接收。

如果是这种情况,你需要在客户端上设置UseSynchronizationContext=false,或者在等待消息接收时避免阻塞。

话虽如此,我对WsDualHttpBinding并没有太多经验。


一个好想法。在这个项目中,我已经遇到了很多线程问题。不幸的是,这个问题似乎不是其中之一(请参见下面我的答案)。 - Ben

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接