简体   繁体   中英

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.

The message could not be transferred within the allotted timeout of 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.

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.

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.

That said, I don't have a ton of experience with WsDualHttpBinding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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