我已经针对wcf pollingduplex绑定创建了一个简单的silverlight客户端:
<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事件恰好发生在一个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-5392250814b8和http://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
解决方法@H_404_61@
我在样本上确认了问题,具有相同的SDK和客户端版本.
这个问题对其他浏览器也有一些影响:我认为MultipleMessagePerPoll似乎也不能正常工作(fiddler和Firebug显示的东西看起来很像SingleMessagePerPoll)
但是,我可以通过使用客户端网络堆栈(绕过浏览器网络堆栈)使其工作.然而,这种解决方案远非完美,因为在这种情况下必须手动设置cookie.根据您的应用,它可能会令人烦恼或无问题.
要通过客户端堆栈执行所有http请求,请在开始服务调用之前使用此请求:
HttpWebRequest.RegisterPrefix("http://",WebRequestCreator.ClientHttp);
然而,根据您的需要,您可以更具体一点.
如果有人有更满意的答案,我会很高兴看到它.如果你有兴趣重现这个问题,我修改了一个旧的Tomek示例,在SL4上使用MultipleMessagePerPoll而不是SL3上的SingleMessagePerPoll.
这个问题对其他浏览器也有一些影响:我认为MultipleMessagePerPoll似乎也不能正常工作(fiddler和Firebug显示的东西看起来很像SingleMessagePerPoll)
但是,我可以通过使用客户端网络堆栈(绕过浏览器网络堆栈)使其工作.然而,这种解决方案远非完美,因为在这种情况下必须手动设置cookie.根据您的应用,它可能会令人烦恼或无问题.
要通过客户端堆栈执行所有http请求,请在开始服务调用之前使用此请求:
HttpWebRequest.RegisterPrefix("http://",WebRequestCreator.ClientHttp);
然而,根据您的需要,您可以更具体一点.
如果有人有更满意的答案,我会很高兴看到它.如果你有兴趣重现这个问题,我修改了一个旧的Tomek示例,在SL4上使用MultipleMessagePerPoll而不是SL3上的SingleMessagePerPoll.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。