<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Scott's Breeze Blog - RFID, BizTalk  - Silverlight</title>
    <link>http://blogs.breeze.net/scotts/</link>
    <description>...and everything in between</description>
    <language>en-us</language>
    <copyright>Breeze Training</copyright>
    <lastBuildDate>Sat, 28 Jun 2008 00:15:38 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>scotts@breezetraining.com.au</managingEditor>
    <webMaster>scotts@breezetraining.com.au</webMaster>
    <item>
      <trackback:ping>http://blogs.breeze.net/scotts/Trackback.aspx?guid=5f9bcff7-ac69-4286-996e-465441f4253d</trackback:ping>
      <pingback:server>http://blogs.breeze.net/scotts/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.breeze.net/scotts/PermaLink,guid,5f9bcff7-ac69-4286-996e-465441f4253d.aspx</pingback:target>
      <dc:creator>Scott Scovell</dc:creator>
      <wfw:comment>http://blogs.breeze.net/scotts/CommentView,guid,5f9bcff7-ac69-4286-996e-465441f4253d.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.breeze.net/scotts/SyndicationService.asmx/GetEntryCommentsRss?guid=5f9bcff7-ac69-4286-996e-465441f4253d</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While working on a BizTalk RFID project we (<a href="http://blogs.breezetraining.com.au/mickb/" target="_blank">Mick</a>, <a href="http://blogs.msdn.com/rgarg/default.aspx" target="_blank">Rahul</a>,
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.
</p>
        <p>
          <a href="http://www.breezetraining.com.au/blogs/scotts/content/binary/SilverlightBeta2andDuplexWCFServices_E8DE/silverlightdisplayinaction.jpg">
            <img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="346" alt="silverlight display in action" src="http://www.breezetraining.com.au/blogs/scotts/content/binary/SilverlightBeta2andDuplexWCFServices_E8DE/silverlightdisplayinaction_thumb.jpg" width="555" border="0" />
          </a>
        </p>
        <p>
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.
</p>
        <p>
At the time we were working with SL 2 Beta 1 and quickly realised two constraining
factors
</p>
        <ol>
          <li>
Silverlight only supports http based WCF bindings. 
</li>
          <li>
Security restrictions prevent the SL application from creating callback listeners.</li>
        </ol>
        <p>
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 <img alt="smile_confused" src="http://spaces.live.com/rte/emoticons/smile_confused.gif" />,
and some help from learned blogger's, we cracked that puppy and got a Silverlight
2 Beta 2 version working. 
</p>
        <p>
Here is a outline of the WCF bits of the Silverlight solution.
</p>
        <ul>
          <li>
Create a new "Silverlight" flavoured WCF service containing both a service contract
and a client callback contract (a duplex service).<br /><br /><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="339" alt="silverlight service contract" src="http://www.breezetraining.com.au/blogs/scotts/content/binary/SilverlightBeta2andDuplexWCFServices_E8DE/silverlightservicecontract.jpg" width="498" border="0" /><br /></li>
          <li>
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.<br /><pre class="csharpcode"><span class="rem">// Obtain a reference to the client callback
channel</span> _callback = OperationContext.Current.GetCallbackChannel&lt;IDuplexServiceCallback&gt;();</pre><style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style></li>
        </ul>
        <p>
          <br />
        </p>
        <ul>
          <li>
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()<br /><pre class="csharpcode"><span class="rem">// Construct NotifyEvent message</span> Message
message = Message.CreateMessage(MessageVersion.Soap11, <span class="str">"Silverlight/IDuplexService/NotifyEvent"</span>,
xmlEventData); <span class="rem">// Push event to client</span> _callback.NotifyEvent(message);<br /><br /></pre></li>
        </ul>
        <ul>
          <li>
Create your own service host and custom binding that uses the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.pollingduplexhttpbinding(VS.95).aspx" target="_blank">PollingDuplexBindingElement</a> located
in the new System.ServiceModel.PollingDuplex assembly in the SL 2 Beta 2 SDK (the
one in the ..\Libraries\<strong>Server</strong>\Evaluation folder).<br /></li>
          <li>
In the SL application we create a duplex polling receiver class (see the <a href="http://msdn.microsoft.com/en-us/library/cc645028(VS.95).aspx" target="_blank">Silverlight
documentation</a> 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. 
<br /></li>
          <li>
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.</li>
        </ul>
        <p>
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, <strong>&lt;ServiceContractNamespace&gt;/&lt;ServiceInterface&gt;/&lt;Operation&gt;</strong>.
</p>
        <p>
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.
</p>
        <p>
Also, <a href="http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx" target="_blank">Dan
Wahlin</a> 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. <img alt="beer" src="http://spaces.live.com/rte/emoticons/beer.gif" /></p>
        <img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=5f9bcff7-ac69-4286-996e-465441f4253d" />
      </body>
      <title>Silverlight 2 Beta 2 and Duplex WCF Services</title>
      <guid isPermaLink="false">http://blogs.breeze.net/scotts/PermaLink,guid,5f9bcff7-ac69-4286-996e-465441f4253d.aspx</guid>
      <link>http://blogs.breeze.net/scotts/2008/06/28/Silverlight2Beta2AndDuplexWCFServices.aspx</link>
      <pubDate>Sat, 28 Jun 2008 00:15:38 GMT</pubDate>
      <description>&lt;p&gt;
While working on a BizTalk RFID project we (&lt;a href="http://blogs.breezetraining.com.au/mickb/" target="_blank"&gt;Mick&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/rgarg/default.aspx" target="_blank"&gt;Rahul&lt;/a&gt;,
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.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.breezetraining.com.au/blogs/scotts/content/binary/SilverlightBeta2andDuplexWCFServices_E8DE/silverlightdisplayinaction.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="346" alt="silverlight display in action" src="http://www.breezetraining.com.au/blogs/scotts/content/binary/SilverlightBeta2andDuplexWCFServices_E8DE/silverlightdisplayinaction_thumb.jpg" width="555" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
At the time we were working with SL 2 Beta 1 and quickly realised two constraining
factors
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Silverlight only supports http based WCF bindings. 
&lt;li&gt;
Security restrictions prevent the SL application from creating callback listeners.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
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 &lt;img alt="smile_confused" src="http://spaces.live.com/rte/emoticons/smile_confused.gif"&gt;,
and some help from learned blogger's, we cracked that puppy and got a Silverlight
2 Beta 2 version working. 
&lt;/p&gt;
&lt;p&gt;
Here is a outline of the WCF bits of the Silverlight solution.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Create a new "Silverlight" flavoured WCF service containing both a service contract
and a client callback contract (a duplex service).&lt;br&gt;
&lt;br&gt;
&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="339" alt="silverlight service contract" src="http://www.breezetraining.com.au/blogs/scotts/content/binary/SilverlightBeta2andDuplexWCFServices_E8DE/silverlightservicecontract.jpg" width="498" border="0"&gt; 
&lt;br&gt;
&lt;li&gt;
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.&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Obtain a reference to the client callback
channel&lt;/span&gt; _callback = OperationContext.Current.GetCallbackChannel&amp;lt;IDuplexServiceCallback&amp;gt;();&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
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()&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;// Construct NotifyEvent message&lt;/span&gt; Message
message = Message.CreateMessage(MessageVersion.Soap11, &lt;span class="str"&gt;"Silverlight/IDuplexService/NotifyEvent"&lt;/span&gt;,
xmlEventData); &lt;span class="rem"&gt;// Push event to client&lt;/span&gt; _callback.NotifyEvent(message);&lt;br&gt;
&lt;br&gt;
&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
Create your own service host and custom binding that uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.pollingduplexhttpbinding(VS.95).aspx" target="_blank"&gt;PollingDuplexBindingElement&lt;/a&gt; located
in the new System.ServiceModel.PollingDuplex assembly in the SL 2 Beta 2 SDK (the
one in the ..\Libraries\&lt;strong&gt;Server&lt;/strong&gt;\Evaluation folder).&lt;br&gt;
&lt;li&gt;
In the SL application we create a duplex polling receiver class (see the &lt;a href="http://msdn.microsoft.com/en-us/library/cc645028(VS.95).aspx" target="_blank"&gt;Silverlight
documentation&lt;/a&gt; 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. 
&lt;br&gt;
&lt;li&gt;
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.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
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, &lt;strong&gt;&amp;lt;ServiceContractNamespace&amp;gt;/&amp;lt;ServiceInterface&amp;gt;/&amp;lt;Operation&amp;gt;&lt;/strong&gt;.
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
Also, &lt;a href="http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx" target="_blank"&gt;Dan
Wahlin&lt;/a&gt; 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. &lt;img alt="beer" src="http://spaces.live.com/rte/emoticons/beer.gif"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.breeze.net/scotts/aggbug.ashx?id=5f9bcff7-ac69-4286-996e-465441f4253d" /&gt;</description>
      <comments>http://blogs.breeze.net/scotts/CommentView,guid,5f9bcff7-ac69-4286-996e-465441f4253d.aspx</comments>
      <category>Silverlight</category>
    </item>
  </channel>
</rss>