Blog Home  Home |  Breeze Home RSS 2.0 Atom 1.0 CDF  
Scott's Breeze Blog - RFID, BizTalk - Silverlight 2 Beta 2 and Duplex WCF Services
...and everything in between
 
# Saturday, June 28, 2008

While working on a BizTalk RFID project we (Mick, Rahul, and I) wanted to explore whether we could use Silverlight (SL) to display tag read events as they are captured. As usual in these scenarios, I started writing wonderfully creative cheque's my graphic design skills could not cash. Eventually I put together an acceptable looking SL page with a couple of animated user controls to represent the received tag read events and counters.

silverlight display in action

The trick was how do we notify the SL application of the tag read event. At first we went down the client polling route and that worked out fine, but we really wanted something akin to duplex communications in WCF. That is, we want the service to push data out to the client when the service receives the event.

At the time we were working with SL 2 Beta 1 and quickly realised two constraining factors

  1. Silverlight only supports http based WCF bindings.
  2. Security restrictions prevent the SL application from creating callback listeners.

Luckily for us Tech.Ed 2008 in the US was running and the team at Microsoft announced Beta 2 with support for a polling duplex communications model. After decoding the beta documentation smile_confused, and some help from learned blogger's, we cracked that puppy and got a Silverlight 2 Beta 2 version working.

Here is a outline of the WCF bits of the Silverlight solution.

  • Create a new "Silverlight" flavoured WCF service containing both a service contract and a client callback contract (a duplex service).

    silverlight service contract
  • Implement the SubscribeToEvents operation ensuring you set a reference to the client callback channel. This is how we send events back to the SL application.
    // Obtain a reference to the client callback channel
    _callback = OperationContext.Current.GetCallbackChannel<IDuplexServiceCallback>();


  • Implement the client callback. In our case, when the WCF service receives a tag read event from BizTalk RFID, we create a new message instance containing the event data and invoke the client callback method NotifyEvent()
    // Construct NotifyEvent message
    Message message = Message.CreateMessage(MessageVersion.Soap11, "Silverlight/IDuplexService/NotifyEvent", xmlEventData);
    
    // Push event to client
    _callback.NotifyEvent(message);

  • Create your own service host and custom binding that uses the PollingDuplexBindingElement located in the new System.ServiceModel.PollingDuplex assembly in the SL 2 Beta 2 SDK (the one in the ..\Libraries\Server\Evaluation folder).
  • In the SL application we create a duplex polling receiver class (see the Silverlight documentation for details) and use the PollingDuplexHttpBinding class to create factory and channel objects to send a message to the service. We then start a message receive loop to listen for messages sent by the service.
  • Received events are then routed to the SL Page class. In our SL Page class we create instances of user controls for each event received and update some running counters.

I did feel some pain around the WCF message formats (see point 3 above). At first I got the message action wrong, but no exceptions were thrown at all warning me of this...the SL application just sat there waiting for the callback. You have to make sure the message action here matches the callback operation exactly. That is, <ServiceContractNamespace>/<ServiceInterface>/<Operation>.

As this is just a POC, I'm sure it will completely change (more than once) as it matures into production ready code, but I thought I might share what we are doing around Silverlight, WCF, and BizTalk.

Also, Dan Wahlin has a great post detailing how to push data to a Silverlight application using WCF duplex services. Much of his work was used to understand how to put all these Silverlight and WCF pieces together. Thanks heaps Dan. beer

Saturday, June 28, 2008 10:15:38 AM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [2]   Silverlight  |  Trackback Tracked by:
"Duplex WCF Services" (Riaan's Blog) [Trackback]
"http://www.google.com/search?q=kuwfkbqh" (http://www.google.com/search?q=kuwfkb... [Pingback]
"http://www.americasbestvalueinn.com/press_article.cfm?nuid=235" (http://www.ame... [Pingback]
"http://www.americasbestvalueinn.com/press_article.cfm?nuid=227" (http://www.ame... [Pingback]
"http://www.google.com/search?q=kwvctjkd" (http://www.google.com/search?q=kwvctj... [Pingback]
"http://www.unep-wcmc.org/GRAMED/viewRecord.cfm?AssID=690909501" (http://www.une... [Pingback]
"http://www.homepower.com/resources/jobs/details/?job_id=312" (http://www.homepo... [Pingback]
"http://www.cda-adc.ca/store/shopexd.asp?id=72" (http://www.cda-adc.ca/store/sho... [Pingback]
"http://www.unsam.edu.ar/infodigital/infodigital.asp?id=1862" (http://www.unsam.... [Pingback]
"http://www.unsam.edu.ar/infodigital/infodigital.asp?id=1893" (http://www.unsam.... [Pingback]
"http://periodismo.educared.org.ar/noticias/comentarios.asp?idn=8875" (http://pe... [Pingback]
"http://www.honar.ac.ir/en/anounce/recall.asp?id=247" (http://www.honar.ac.ir/en... [Pingback]
"http://www.89fm.com.br/promo/?ID=544" (http://www.89fm.com.br/promo/?ID=544) [Pingback]
"http://www.89fm.com.br/promo/?ID=620" (http://www.89fm.com.br/promo/?ID=620) [Pingback]
"http://www.89fm.com.br/promo/?ID=614" (http://www.89fm.com.br/promo/?ID=614) [Pingback]
"http://www.newstalkzb.co.nz/newsdetail1.asp?storyID=165544" (http://www.newstal... [Pingback]
"http://www.newstalkzb.co.nz/newsdetail1.asp?storyID=165564" (http://www.newstal... [Pingback]
"http://www.nsca-lift.org/webnews/detlnews.asp?news=1212" (http://www.nsca-lift.... [Pingback]
"http://www.nsca-lift.org/webnews/detlnews.asp?news=1192" (http://www.nsca-lift.... [Pingback]
"http://jobs.mammothmountain.com/season/jobdetail.cfm?opening_id=996292833" (htt... [Pingback]
"http://www.fieb.org.br/iel/bitec/default.asp?id=62" (http://www.fieb.org.br/iel... [Pingback]
"http://www.fieb.org.br/iel/bitec/default.asp?id=61" (http://www.fieb.org.br/iel... [Pingback]
"http://webapp.rlc.edu/pressroom/printstory.php?id=3540" (http://webapp.rlc.edu/... [Pingback]
"http://webapp.rlc.edu/pressroom/printstory.php?id=2594" (http://webapp.rlc.edu/... [Pingback]
"http://www.mutualfundsindia.com/fund_facts_rpt.asp?scheme=hgfztxez" (http://www... [Pingback]
"http://www.mutualfundsindia.com/indusind/fund_facts_rpt.asp?scheme=vyhnxgrv" (h... [Pingback]
"http://www.mutualfundsindia.com/fund_facts_rpt.asp?scheme=funqlwzp" (http://www... [Pingback]
"http://www.sunway.com.my/webgroups/gpa_press_archivepopup.asp?id=746" (http://w... [Pingback]
"http://www.biotec.or.th/BCC/Medium.asp?Mkey=142" (http://www.biotec.or.th/BCC/M... [Pingback]
"http://www.google.com/search?q=mjbxpusv" (http://www.google.com/search?q=mjbxpu... [Pingback]
"http://www.latinol.com/cine/v5-articulo.asp?id=658" (http://www.latinol.com/cin... [Pingback]
"http://www.latinol.com/cine/v5-articulo.asp?id=1071" (http://www.latinol.com/ci... [Pingback]
"http://www.dibam.cl/adjuntos.asp?id_docAdjunto=168974534" (http://www.dibam.cl/... [Pingback]
"http://www.dibam.cl/adjuntos.asp?id_docAdjunto=160483530" (http://www.dibam.cl/... [Pingback]
"http://www.latinol.com/cine/v5-articulo.asp?id=1407" (http://www.latinol.com/ci... [Pingback]
"http://www.latinol.com/cine/v5-articulo.asp?id=1659" (http://www.latinol.com/ci... [Pingback]
"http://www.fotbal.cz/zprava.php?id=537752839" (http://www.fotbal.cz/zprava.php?... [Pingback]
"http://www.janubaba.com/buynsell/viewad.asp?AdId=40008" (http://www.janubaba.co... [Pingback]
"http://www.janubaba.com/buynsell/viewad.asp?AdId=40050" (http://www.janubaba.co... [Pingback]
"http://www.google.com/search?q=pbwsgyoz" (http://www.google.com/search?q=pbwsgy... [Pingback]
"http://www.google.com/search?q=rnarnjwe" (http://www.google.com/search?q=rnarnj... [Pingback]
"http://www.mwti.net/virus_info/virusalertd.asp?vid=1194" (http://www.mwti.net/v... [Pingback]
"http://www.mwti.net/virus_info/virusalertd.asp?vid=1166" (http://www.mwti.net/v... [Pingback]
"http://www.google.com/search?q=ywnrbshd" (http://www.google.com/search?q=ywnrbs... [Pingback]
"http://www.anaheimoc.org/press/pressNews.asp?pid=521" (http://www.anaheimoc.org... [Pingback]
"http://www.anaheimoc.org/press/pressNews.asp?pid=506" (http://www.anaheimoc.org... [Pingback]
"http://en.hardspell.com/doc/enshowcont.asp?id=7351" (http://en.hardspell.com/do... [Pingback]
"http://en.hardspell.com/doc/enshowcont.asp?id=7349" (http://en.hardspell.com/do... [Pingback]
"http://www.akampus.com/kampus_online/kol/kampus_online_news.asp?news=2012" (htt... [Pingback]
"http://www.akampus.com/kampus_online/kol/kampus_online_news.asp?news=2076" (htt... [Pingback]
"http://www.vaneduc.edu.ar/uai/Extension/uai-cursos.asp?id=370543359" (http://ww... [Pingback]
"http://www.vaneduc.edu.ar/uai/Extension/uai-cursos.asp?id=301253035" (http://ww... [Pingback]
"http://nv.fotbal.cz/en-national-teams/zprava.php?id=621086969" (http://nv.fotba... [Pingback]
"http://www.njbiz.com/people.asp?pID=5129" (http://www.njbiz.com/people.asp?pID=... [Pingback]
"http://www.njbiz.com/people.asp?pID=5156" (http://www.njbiz.com/people.asp?pID=... [Pingback]
"http://www.recruitgulf.com/member.asp?MID=306" (http://www.recruitgulf.com/memb... [Pingback]
"http://www.recruitgulf.com/member.asp?MID=286" (http://www.recruitgulf.com/memb... [Pingback]
"http://moviesberry.com/vids/vid_dana_carvey_squatting_monkeys_tell_no_lies.html... [Pingback]
Sunday, August 10, 2008 5:11:27 AM (AUS Eastern Standard Time, UTC+10:00)
Here is a question for you that I have yet to get answered.. I have now seen an example of a consuming a WCF duplex service using silverlight, but what about if you just want to call your regular WCF service in silverlight but you want to maintain your own silverlight business objects instead of the proxy objects that are created using svcutil? Normally if you were consuming from WPF, you could just call ChannelFactory.CreateChannel, but this apparantly isn't supported in Silverlight 2 Beta 2 (http://tinyurl.com/5e52gs). Assuming you just want to get your data in this way, what is the best way to do this? Now assuming that you can call CreateChannel in Silverlight 2 RTM, what are your thoughts on using this method while still maintaining a responsive UI? In Silverlight 2, when you Add Service Reference, it generates your proxy service which extends ClientBase and automatically handles the calls to your service asynchronously, but that probably won't be available when using a transparent proxy... Any thoughts on this? Will you need to provide your own threading? I really haven't seen anybody discussing this type of idea.
Friday, February 06, 2009 9:18:24 AM (AUS Eastern Daylight Time, UTC+11:00)
Take a look at this for silverlight callback event demo

http://www.scrumwall.com/scrumwall.aspx
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2010 Breeze Training. All rights reserved.