Silverlight PollingDuplex InnerChannel与multipleMessagesPerPoll(serverPollTimeout)出现故障

时间:2010-11-15 12:50:00

标签: silverlight wcf pollingduplexhttpbinding

我正在运行Silverlight客户端版本4.0.50917.0和SDK版本4.0.50826.1

我已经针对wcf pollingduplex绑定创建了一个简单的silverlight客户端:

的Web.config:

<system.serviceModel>
<extensions>
  <bindingExtensions>
    <add name="pollingDuplexHttpBinding"
        type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </bindingExtensions>
</extensions>
<behaviors>
  <serviceBehaviors>
    <behavior name="sv">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentSessions="2147483647"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <!-- Create the polling duplex binding. -->
  <pollingDuplexHttpBinding>
    <binding name="multipleMessagesPerPollPollingDuplexHttpBinding"
             duplexMode="MultipleMessagesPerPoll"
             maxOutputDelay="00:00:01"/>

    <binding name="singleMessagePerPollPollingDuplexHttpBinding"
             maxOutputDelay="00:00:01"/>
  </pollingDuplexHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="sv" name="Backend.GUIPollingService">
    <endpoint address="" binding="pollingDuplexHttpBinding" bindingConfiguration="singleMessagePerPollPollingDuplexHttpBinding"
      contract="Backend.IGUIPollingService" />
    <endpoint address="mmpp" binding="pollingDuplexHttpBinding" bindingConfiguration="multipleMessagesPerPollPollingDuplexHttpBinding"
      name="multimessage" contract="Backend.IGUIPollingService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

我的silverlight客户端连接如下:

 string endPointAddress2 = "http://"
          + App.Current.Host.Source.DnsSafeHost
          + ":"
          + App.Current.Host.Source.Port.ToString(CultureInfo.InvariantCulture)
          + "/GUIPollingService.svc/mmpp";
 this.client = new GUIClientProxy.GUIPollingServiceClient(
        new PollingDuplexHttpBinding(PollingDuplexMode.MultipleMessagesPerPoll), 
        new EndpointAddress(endPointAddress2))

我为innerchannel故障找到了一个事件处理程序:

client.InnerChannel.Faulted += new EventHandler(InnerChannel_Faulted);

...

void InnerChannel_Faulted(object sender, EventArgs e)
    {

        Dispatcher.BeginInvoke(() =>
        { status.Text += "Inner channel Faulted\n\n"
        }
    } 

使用上述内容时,Client.InnerChannelFaulted事件恰好发生在 one serverPollTimeout之后。 (默认为15秒,用Fiddler验证)

如果我将客户端切换为这样连接:

string endPointAddress2 = "http://"
          + App.Current.Host.Source.DnsSafeHost
          + ":"
          + App.Current.Host.Source.Port.ToString(CultureInfo.InvariantCulture)
          + "/GUIPollingService.svc";
 this.client = new GUIClientProxy.GUIPollingServiceClient(
        new PollingDuplexHttpBinding(), 
        new EndpointAddress(endPointAddress2))

每个民意调查的单个消息fiddler显示,在每个serverPollTimeout之后,新的民意调查开始并且频道出现故障。

这里有什么想法吗?

编辑:

我看过http://social.msdn.microsoft.com/Forums/en/wcf/thread/1e6aa407-4446-4d4a-8dac-5392250814b8http://forums.silverlight.net/forums/p/200659/468206.aspx#468206 我同意“singleMessagePerPoll”不是一个体面的解决方法。正如您在我的版本中看到的那样,我正在运行最新版本的SDK和开发人员运行时。

EDIT2:

我刚刚发现,如果我使用谷歌浏览器作为浏览器而不是IE8 MultipleMessagesPerPoll工作正常!对我来说,这有点像运行时与ie8的错误?

EDIT3:

在Silverlight WS博客上确认: http://blogs.msdn.com/b/silverlightws/archive/2010/12/15/pollingduplex-using-multiplemessagesperpoll-issue-in-latest-sl4-gdrs.aspx

2 个答案:

答案 0 :(得分:3)

我使用相同的SDK和客户端版本确认了样本上的问题。

这个问题对其他浏览器也有一些影响:我认为MultipleMessagePerPoll似乎也不能正常工作(Fiddler和Firebug显示的东西看起来很像SingleMessagePerPoll)

但是我可以通过使用客户端网络堆栈(绕过浏览器网络堆栈)使其工作。然而,这种解决方案远非完美,因为在这种情况下必须手动设置cookie。根据您的申请,它可能会令人烦恼或无问题。

要通过客户端堆栈执行所有http请求,请在开始服务调用之前使用此命令:

HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);

然而,根据您的需要,您可以更具体一点。

如果有人有更令人满意的答案,我会很高兴看到它。如果你有兴趣重现这个问题,我修改了一个旧的Tomek示例,在SL4上使用MultipleMessagePerPoll而不是SL3上的SingleMessagePerPoll。

答案 1 :(得分:1)

将global.asax添加到托管网站可能会导致此问题。向主机站点添加会话显然会破坏wcf轮询双工服务。我在这个问题上挣扎了好几天,只是从主机网站上删除了global.asax文件,服务中的挂起就消失了。多重消息是错误的领导。它工作正常。

请参阅此内容以获取更多信息:

How can a newly added global.asax file make a mess of my WCF service

相关问题