Silverlight: WCF duplex communication learning notes

Source: Internet
Author: User
I have always thought that the WCF duplex communication method in Sl is a little tricky. If it is implemented in http mode, the efficiency is too low. If it is implemented in TCP mode in sl4, it is the same as socket, so I have not studied it, however, this is easy to implement when the performance requirement is not high (for example, the weather forecast/stock information is updated every five minutes on the webpage.

Compared with traditional WCF, the biggest difference between WCF duplex communication is that traditional WCF usually calls services from clients, that is, the client pulls information from the server, in addition to allowing the client to pull information from the server, the server can also actively push information to the client.

Of course, this implementation consumes performance. The server will save a "Callback channel" so that information can be pushed to the client through this channel, the client also needs to have corresponding callback functions to handle them-a bit similar to "long links in Ajax" and "server push" Technology

Sl3 official documentation http://msdn.microsoft.com/zh-cn/library/dd470106 (vs.95 ). in aspx, a client sends the order to the server and then forwards the result back to the client after processing by the server. However, there are two parts in the SDK that do not indicate the details, debugging failure may be misled.

1. If bindingextensions is configured in Web. config of the server, follow the official configuration instructions:

<Extensions>
<Bindingextensions>
<Add name = "pollingduplexhttpbinding"
Type = "system. servicemodel. configuration. pollingduplexhttpbindingcollectionelement, system. servicemodel. pollingduplex, Version = 2.0.5.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>
</Bindingextensions>
</Extensions>

Prompt will be displayed when you browse SVCProgramFailed to load the set. In this case, remove ", version = 2.0.5.0, culture = neutral, publickeytoken = 31bf3856ad364e35" above and change it

<Extensions>
<Bindingextensions>
<Add name = "pollingduplexhttpbinding" type = "system. servicemodel. configuration. pollingduplexhttpbindingcollectionelement, system. servicemodel. pollingduplex"/>
</Bindingextensions>
</Extensions>

In addition, if system. servicemodel. pollingduplex. dll is not found in the bin directory after generation, you can manually copy it to the bin directory.

2. If the client cannot access the client during debugging, check whether there is a policy file clientaccesspolicy. xml on the server. The reference content is as follows:

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

Source codeDownload: duplexwcf_sl.rar (edited by vs2010, which may need to be manually modified when opened in vs2008)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.