简体   繁体   English

WCF:遇到单向回调问题

[英]WCF: Having trouble with one-way callbacks

I keep getting this puzzling error upon invocation of a one-way callback to a WPF client from a WCF service. 从WCF服务调用WPF客户端的单向回调时,我不断遇到这个令人费解的错误。

The message could not be transferred within the allotted timeout of 00:01:00. 消息无法在分配的00:01:00超时内传输。 There was no space available in the reliable channel's transfer window. 可靠频道的传输窗口中没有可用空间。 The time allotted to this operation may have been a portion of a longer timeout. 分配给此操作的时间可能是较长超时的一部分。

It isn't sending too much data, just a list of strings that only has one single, short string within. 它不会发送太多数据,只是一个只有一个短字符串的字符串列表。

My server has the following config: 我的服务器有以下配置:

<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>

And my client has the following config: 我的客户端有以下配置:

<?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>

Its just baffling that this could happen, given that the message is relatively small and the callback is only one-way. 考虑到消息相对较小并且回调只是单向的,这可能会发生这种情况令人困惑。 Should I try some different bindings? 我应该尝试一些不同的绑定吗?

I found the issue, and its unfortunate that this particular error message sent me down a completely wrong path. 我发现了这个问题,不幸的是,这个特殊的错误信息让我走上了一条完全错误的道路。

My DataContract setup had some classes with inheritance in it, and I hadn't properly marked for KnownType s. 我的DataContract设置有一些继承的类,我没有正确标记为KnownType

My guess is at some point the client tried to de-serialize an associated object and failed. 我的猜测是在某些时候客户端试图反序列化一个相关的对象并失败了。 The error must not have been handled gracefully by the framework, and perhaps it kept trying to send over and over, and got no response after a minute. 错误一定不是由框架优雅地处理的,也许它一直在尝试一遍又一遍地发送,并且在一分钟后没有得到响应。

Perhaps if I had a two-way call I would have gotten a more informative stack trace. 也许如果我有一个双向通话,我会得到一个更丰富的堆栈跟踪。

It smells like a blocking/threading issue rather than a networking issue. 它闻起来像一个阻塞/线程问题而不是网络问题。

By any chance are you doing any kind of blocking/waiting for the one-way message to be received on the client? 您是否有任何机会阻止/等待客户端收到的单向消息? If so, and you're using the synchronization context, you're deadlocking WCF - blocking the message queue waiting for the message, while the message can't be received until the message queue is unblocked. 如果是这样,并且您正在使用同步上下文,则会使WCF死锁 - 阻塞等待消息的消息队列,而在消息队列被解除阻塞之前无法接收消息。

If this is the case, you'll need to either set UseSynchronizationContext=false on your client, or avoid blocking while waiting for the message to be received. 如果是这种情况,您需要在客户端上设置UseSynchronizationContext=false ,或者在等待接收消息时避免阻塞。

That said, I don't have a ton of experience with WsDualHttpBinding. 也就是说,我对WsDualHttpBinding没有太多经验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM