前段时间使用WCF做了一个消息系统,本来采用的是双工通信模式,但由于将服务寄宿到IIS后,当客户端掉线时,服务端会因为无法调用客户端而产生一个导致IIS进程崩溃的异常。
今天跟同事聊了一些事情,觉得自己克服困难的能力还是不够,决定继续研究一下这个异常问题,今天暂时将Silverlight离线帮助文档中的例子调试通过了,准备下面的改造工作。
总结了一下,WCF双工服务,基本是会配置即会使用的,有几个关键的地方需要注意:
1,建立服务时最好建立独立的Project。
2,WCF的Project记得引用C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Server下的System.ServiceModel.PollingDuplex.dll文件,这个是做双工通信所需的通信模式。
3,WCF服务的根文件夹下需要放一个策略文件clientaccesspolicy.xml
<?
xml version="1.0" encoding="utf-8"
?>
< access-policy >
< cross-domain-access >
< policy >
< allow-from http-request-headers ="SOAPAction" >
< domain uri ="*" />
</ allow-from >
< grant-to >
< resource path ="/" include-subpaths ="true" />
</ grant-to >
</ policy >
</ cross-domain-access >
</ access-policy >
< access-policy >
< cross-domain-access >
< policy >
< allow-from http-request-headers ="SOAPAction" >
< domain uri ="*" />
</ allow-from >
< grant-to >
< resource path ="/" include-subpaths ="true" />
</ grant-to >
</ policy >
</ cross-domain-access >
</ access-policy >
4,在服务的接口说明中要声明客户端的回调
[ServiceContract(CallbackContract
=
typeof
(IDuplexClient))]
5,Webconfig中需要先注册pollingDuplexHttpBinding方式后才能在后续的配置中使用这种方式
<
extensions
>
< bindingExtensions >
< add name ="pollingDuplexHttpBinding"
type ="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex,
Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</ bindingExtensions >
</ extensions >
< bindingExtensions >
< add name ="pollingDuplexHttpBinding"
type ="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex,
Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</ bindingExtensions >
</ extensions >
6,如果是基于http协议的访问需要
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。