<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>IRhetoric - Karsten Januszewski   : WCF</title><link>http://blogs.msdn.com/karstenj/archive/tags/WCF/default.aspx</link><description>Tags: WCF</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Windows Communication Foundation (WCF) Coding Practices By IDesign</title><link>http://blogs.msdn.com/karstenj/archive/2006/12/06/windows-communication-foundation-wcf-coding-practices-by-idesign.aspx</link><pubDate>Thu, 07 Dec 2006 02:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1224960</guid><dc:creator>karstenj</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/karstenj/comments/1224960.aspx</comments><wfw:commentRss>http://blogs.msdn.com/karstenj/commentrss.aspx?PostID=1224960</wfw:commentRss><description>&lt;P&gt;When doing some WCF coding not too long ago, I came across the &lt;A class="" href="http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&amp;amp;tabid=11" target=_blank mce_href="http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&amp;amp;tabid=11"&gt;IDesign code samples&lt;/A&gt; by Juval Lowry, whose work I was familiar with from MSDN magazine.&amp;nbsp; IDesign just recently &lt;A class="" href="http://www.idesign.net/idesign/download/IDesign%20WCF%20Coding%20Standard.zip" target=_blank mce_href="http://www.idesign.net/idesign/download/IDesign%20WCF%20Coding%20Standard.zip"&gt;published a paper on WCF coding guidelines&lt;/A&gt; which I would highly recommend.&amp;nbsp; The paper is short and sweet and cuts to the chase of many best practices for WCF that can be difficult to understand from the SDK.&amp;nbsp; When working with a platform as&amp;nbsp;vast as WCF, this comes in very handy. &lt;/P&gt;
&lt;P&gt;We need the corresponding document for WPF.&amp;nbsp; &amp;nbsp; &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1224960" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/karstenj/archive/tags/WCF/default.aspx">WCF</category></item><item><title>WCF Calls Hanging Without Any Debug or Fault Information</title><link>http://blogs.msdn.com/karstenj/archive/2006/11/15/wcf-calls-hanging-without-any-debug-or-fault-information.aspx</link><pubDate>Wed, 15 Nov 2006 21:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1081791</guid><dc:creator>karstenj</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/karstenj/comments/1081791.aspx</comments><wfw:commentRss>http://blogs.msdn.com/karstenj/commentrss.aspx?PostID=1081791</wfw:commentRss><description>&lt;P&gt;I recently encountered a confusing issue with WCF.&amp;nbsp; An application that worked fine on RC1 suddenly started intermittently failing on the release build of .NET 3.0.&amp;nbsp; What was most perplexing was that no errors were returned, no debug information was provided, nothing.&amp;nbsp; Calls from the client to the server never returned but just hung and the server provided no fault information.&amp;nbsp; It was as if messages just went into the aether.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;After some consultation with the WCF team, it was determined that changes to the default &lt;STRONG&gt;serviceThrottling&lt;/STRONG&gt; behavior between builds was the culprit.&amp;nbsp; The defaults are 16 &lt;STRONG&gt;MaxConcurrentCalls&lt;/STRONG&gt; and 10 &lt;STRONG&gt;MaxConcurrentSessions&lt;/STRONG&gt;, which was changed between RC1 and the final release.&amp;nbsp; So, the calls from the client truly were heading into the aether and the server wasn't able to provide any information because it wasn't able to even process them. Why was the server getting so hammered from just a single client? In this case, the client was spawning multiple threads (~10 proxies) and issuing multiple asynchronous requests (~15) from each proxy.&amp;nbsp; You do the math and you can see what was happening.&lt;/P&gt;
&lt;P&gt;The fix was to do two things.&amp;nbsp; First, the &amp;lt;behaviors&amp;gt; section of the app.config file was updated as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;behaviors&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;serviceBehaviors&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;behavior name="NewBehavior"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/behavior&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/serviceBehaviors&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/behaviors&amp;gt;&lt;/P&gt;
&lt;P&gt;Note that I'm not an WCF expert and I'm not sure the sweet spot as far as performance vs. throughput when tweaking these numbers.&lt;/P&gt;
&lt;P&gt;The other thing that was done to the application was to reel back the client a bit so that it wasn't hammering the server with so many simultaneous requests. Fewer proxies were spawned and fewer requests were sent.&amp;nbsp; There was no degradation in performance when doing this, as the client couldn't handle all the responses it got anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The moral of the story?&amp;nbsp; If your WCF service starts misbehaving without any diagnostics, this may be the culprit.&lt;/P&gt;
&lt;P&gt;Oh, and if you are still editing your WCF &lt;STRONG&gt;app.config&lt;/STRONG&gt; file by hand, then you must immediately open &lt;STRONG&gt;SvcConfigEditor.exe&lt;/STRONG&gt; from the SDK bin.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1081791" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/karstenj/archive/tags/Windows+Communication+Foundation/default.aspx">Windows Communication Foundation</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/WCF/default.aspx">WCF</category></item><item><title>Inter Process Communication Between Applications and Vista Gadgets Using WCF (Part 2) </title><link>http://blogs.msdn.com/karstenj/archive/2006/10/20/WPF_5F00_WCF_5F00_Vista_5F00_Gadgets_5F00_2.aspx</link><pubDate>Sat, 21 Oct 2006 01:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:851327</guid><dc:creator>karstenj</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/karstenj/comments/851327.aspx</comments><wfw:commentRss>http://blogs.msdn.com/karstenj/commentrss.aspx?PostID=851327</wfw:commentRss><description>&lt;P&gt;Once I got WCF working in a gadget, another scenario came up: wouldn't it be nice if the gadget and the application shared a data model?&amp;nbsp; The gadget could remotely databind to the same data that the application was databound to.&amp;nbsp; As such, there would be one data source, owned by the application, that the gadget could both manipulate as well as receive updates when things changed.&amp;nbsp; To be clear, there are not two data sources that I am trying to keep in sync, but rather one data source owned by the application which the gadget reads and writes to.&amp;nbsp; (It does have a "local copy" but from the code never touches the "local copy" and only manipulates the data source through its proxy class to the master copy.) I wanted to use as much of the WPF databinding as I could to try and get some of the databinding goodness for free.&amp;nbsp; I based the code on a sample in the SDK under the WCF samples called Data Binding in a Windows Presentation Client.&amp;nbsp; Also, I found this &lt;A class="" href="http://blogs.sqlxml.org/bryantlikes/archive/2006/09/20/Enabling-WPF-Magic-Using-WCF-_2D00_-Part-2.aspx" mce_href="http://blogs.sqlxml.org/bryantlikes/archive/2006/09/20/Enabling-WPF-Magic-Using-WCF-_2D00_-Part-2.aspx"&gt;blog post&lt;/A&gt; helpful.&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip" mce_href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip"&gt;Download the code and gadgets&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The architecture is different than my earlier example because there is a more pure client/server relationship between the application and the gadget. The application acts purely as the server and really could care less if it has any clients.&amp;nbsp;&amp;nbsp; The gadget acts as a client only, unlike my earlier sample.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Similar to my earlier sample, I removed the metadata exchange and share type between projects.&amp;nbsp; Again, because no one else will be using the service, it turns out to be simpler to just share the code and not rely on the proxy code generation tool.&amp;nbsp; In this case, I have have data contracts shared as well as contract.&amp;nbsp; The contract itself is a bit trickier because I am using a Duplex channel, which is what allows the application to notify the gadget that data has changed.&amp;nbsp; As such, I decorate the contract with the &lt;STRONG&gt;SessionMode=SessionMode.Required&lt;/STRONG&gt; attribute.&amp;nbsp; I then decorate the server implementation of the contract with&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,ConcurrencyMode = ConcurrencyMode.Multiple)]&lt;/STRONG&gt;.&amp;nbsp; Notice that I still have an &lt;STRONG&gt;InstanceContextMode&lt;/STRONG&gt; of single, so that I only have one instance of the service object, but I allow a ConcurrencyMode of multiple, so that if there were multiple clients to the service, all would still be hunky dory.&amp;nbsp; (Thanks to &lt;A class="" href="http://blogs.msdn.com/craigmcmurtry/" mce_href="http://blogs.msdn.com/craigmcmurtry/"&gt;Craig McMurtry&lt;/A&gt; for helping understand the right choices to make here.) &lt;/P&gt;
&lt;P&gt;In the implementation of the service, I used a trick I picked up from the fantastic samples up at the &lt;A class="" href="http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&amp;amp;tabid=11" mce_href="http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&amp;amp;tabid=11"&gt;IDesign&lt;/A&gt; site.&amp;nbsp; Basically, I use their technique of registering a list of clients through the use of a &lt;STRONG&gt;Connect&lt;/STRONG&gt; method.&amp;nbsp; Once a client is registered, it can be called back from the server.&amp;nbsp; The convention of &lt;STRONG&gt;Disconnect&lt;/STRONG&gt; allows the server to clean up any subscribers. Nice!&lt;/P&gt;
&lt;P&gt;As I mentioned earlier, I wanted to try to preserve as much databinding goodness as I could.&amp;nbsp; As such, I subclasses &lt;STRONG&gt;ObservableCollection&lt;/STRONG&gt; and overrode the &lt;STRONG&gt;OnCollectionChanged&lt;/STRONG&gt; event.&amp;nbsp; It is within this event that I callback to any listeners to let them know that the data has changed.&amp;nbsp; Unfortunately, I couldn't simply serialize the &lt;STRONG&gt;NotifyCollectionChangedEventArgs&lt;/STRONG&gt;.&amp;nbsp; As such, it would take quite a bit of custom code to truly serialize this event -- looking at Reflector is a good start if you are interested in doing this.&amp;nbsp; For my purposes, I just notify the client that the data has changed so that they can rebind.&amp;nbsp; It is worth calling out that this same technique could be used to serialize the &lt;STRONG&gt;INotifyPropertyChanged&lt;/STRONG&gt; event as well, for more granular control over changes instead of the brute force approach I took here.&lt;/P&gt;
&lt;P&gt;One thing I do in the client (which I also learned from the IDesign site) was to create my own asynchronous proxy class, rather than having the svcutil tool generate it for me. I then use a slightly different technique in instantiating the client than I did in &lt;A class="" href="http://blogs.msdn.com/karstenj/archive/2006/10/20/WPF-WCF-Vista-Gadgets.aspx" mce_href="http://blogs.msdn.com/karstenj/archive/2006/10/20/WPF-WCF-Vista-Gadgets.aspx"&gt;part 1&lt;/A&gt;. This time, I create a &lt;STRONG&gt;DuplexChannelFactory&lt;/STRONG&gt; which I use to new up clients to the service. Another thing I did was not use config files but rather I have things like the endpoint hardcoded into the app -- more secure.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do something simliar as I did in &lt;A class="" href="http://blogs.msdn.com/karstenj/archive/2006/10/20/WPF-WCF-Vista-Gadgets.aspx" mce_href="http://blogs.msdn.com/karstenj/archive/2006/10/20/WPF-WCF-Vista-Gadgets.aspx"&gt;part 1&lt;/A&gt; as far as making the gadget reliable in the event that the application isn't running by wrapping the initial &lt;STRONG&gt;Connect&lt;/STRONG&gt; operation in a do/while statement, nulling out a client object if it fails to connect. &lt;/P&gt;
&lt;P&gt;The asynchronous databinding is entirely lifted from the SDK sample other than the moment where I get a callback.&amp;nbsp; At first I tried to call the service as soon as I received the &lt;STRONG&gt;CollectionChanged&lt;/STRONG&gt; notification.&amp;nbsp; However, this created a race condition.&amp;nbsp; So, I call the service on a background thread when I receive the callback, which worked out fine. &lt;/P&gt;
&lt;P&gt;The WPF code itself is wrapped up in an ActiveX control, as discussed &lt;A class="" href="http://blogs.msdn.com/karstenj/archive/2006/10/09/activex-wpf-gadget.aspx" mce_href="http://blogs.msdn.com/karstenj/archive/2006/10/09/activex-wpf-gadget.aspx"&gt;in this post&lt;/A&gt;.&amp;nbsp; Nothing new here. Of course, installing the ActiveX control requires elevation. &lt;/P&gt;
&lt;P&gt;So, to get the sample working, first run the install.cmd from a cmd prompt run as administrator to register the ActiveX control.&amp;nbsp; Then, compile the databinding_serv.sln file in the sources directory.&amp;nbsp; Again, if you don't have VS on your Vista box, you can use &lt;A class="" href="http://blogs.msdn.com/tims/archive/2006/04/05/569504.aspx" mce_href="http://blogs.msdn.com/tims/archive/2006/04/05/569504.aspx"&gt;this trick from Tim Sneath&lt;/A&gt;&amp;nbsp;to compile from a command line. You'll notice that the gadget binds to the application's data whenever the application comes online.&amp;nbsp; If you update the data in the application, the gadget will get updated.&amp;nbsp; And if you update the data in the gadget, the application's data is updated.&amp;nbsp;&amp;nbsp; Note that I never manipulate the data directly within the gadget, but always through the proxy.&amp;nbsp; Also, note that I rebind to the gadget data every time, which isn't super efficient and could be a problem with larger data sets.&amp;nbsp; Of course, it is communication on the same box, which is pretty darned fast.&amp;nbsp; Go WCF!&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip" mce_href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip"&gt;Download the code and gadgets&lt;/A&gt;.&lt;BR&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=851327" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/karstenj/archive/tags/Windows+Presentation+Foundation+_2800_Avalon_2900_/default.aspx">Windows Presentation Foundation (Avalon)</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/Vista/default.aspx">Vista</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/Windows+Communication+Foundation/default.aspx">Windows Communication Foundation</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/WCF/default.aspx">WCF</category></item><item><title>Inter Process Communication Between Applications and Vista Gadgets Using WCF (Part 1)</title><link>http://blogs.msdn.com/karstenj/archive/2006/10/20/WPF-WCF-Vista-Gadgets.aspx</link><pubDate>Sat, 21 Oct 2006 00:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:851106</guid><dc:creator>karstenj</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/karstenj/comments/851106.aspx</comments><wfw:commentRss>http://blogs.msdn.com/karstenj/commentrss.aspx?PostID=851106</wfw:commentRss><description>&lt;P&gt;I recently faced the design challenge of getting an application and gadget to communicate. How to solve the problem? Well, what better way to talk between applications than Windows Communication Foundation (WCF).&amp;nbsp; After all, it is the inheritor of the .NET Remoting legacy, which is what would be used in the past. It was quite enjoyable to return to writing WCF code, which I hadn't done for awhile. It really is the analog to WPF in terms of beautifully factored code architecture.&amp;nbsp; In part 1, I'll show my first prototype, which used an XBAP gadget acting as both a server and a client that sends mouse movements over WCF to trackball either the application or the gadget.&amp;nbsp; In part 2, I'll show my second prototype, which shows an ActiveX-based gadget acting as a client to the application and databinding to the application's data model.&amp;nbsp; I subclass &lt;STRONG&gt;ObservableCollection&lt;/STRONG&gt; and show the beginnings of what I dubbed &lt;STRONG&gt;SerializedObservableCollection&lt;/STRONG&gt;.&amp;nbsp; &lt;A class="" href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip" mce_href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip"&gt;Download the code and gadgets.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Before explaining how I went about coding this, please be aware of all the &lt;A class="" href="http://blogs.msdn.com/karstenj/archive/2006/10/04/WPF-Vista-Gadgets-_2D00_-Part-1_3A00_-Using-XBAP-and-IFRAME.aspx" target=_blank mce_href="http://blogs.msdn.com/karstenj/archive/2006/10/04/WPF-Vista-Gadgets-_2D00_-Part-1_3A00_-Using-XBAP-and-IFRAME.aspx"&gt;issues with WPF gadgets raised in this post&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://winfx.members.winisp.net/files/wcf.jpg"&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Part 1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The first project remotes mouse move behaviors such that you can trackball the gadget and change the application.&amp;nbsp; Or, you can trackball the application and update the gadget.&amp;nbsp; In this case, the gadget is an XBAP.&amp;nbsp; Now, because XBAPs run in partial trust, I had to change the XBAP security settings to allow for WCF, which requires full trust.&amp;nbsp; This was just a matter of tweaking the settings in the security tab of the project properties.&amp;nbsp; Because the XBAP is being launched from the file system, this does not present any deployment problems.&amp;nbsp; Were the XBAP to be deployed from a serer, the certificate used to sign the XBAP needs to be installed in the trusted publishers list on the user's machine.&amp;nbsp; In an installation routine, one could call &lt;STRONG&gt;certmgr /i&lt;/STRONG&gt; under the covers.&amp;nbsp; The other option here would be to place the WCF code in a seperate assembly marked as Allow Partially Trusted Callers (APTCA) and register it in the GAC.&amp;nbsp; To protect the APTCA assembly, it should be locked down using FriendsAssembly concept (InternalsVisibleTo). That way only the Xbap that put the APTCA assembly can call into it. In this case, XBAP itself can stay in sandbox but APTCA assembly acts as a proxy between XBAP and full trust calls. I haven't done this myself but I've been told it works.&lt;/P&gt;
&lt;P&gt;The way the WCF architecture works in this sample is that the gadget and application each act as both a server and a client.&amp;nbsp; So, when you are trackballing the gadget, it is acting as a client to the application and sends messages about mouse position to the application, which is listening.&amp;nbsp; As soon as the application is trackballed, the roles flip and the application then acts as the client and sends its mouse events to the gadget, which listens as a server.&lt;/P&gt;
&lt;P&gt;All the communication uses the &lt;STRONG&gt;netNamedPipe&lt;/STRONG&gt; binding of WCF. This is established in the app.config file.&amp;nbsp; One interesting fact is that the messages between the app and gadget are signed and encrypted, which is cool. No other rogue application could sniff the traffic between the gadget and application.&amp;nbsp; I have turned off the metadata exchange features of WCF.&amp;nbsp; This means that to create my client proxy for talking to the service, I had to either use svcutil.exe on the application itself or, rather than generate a client, I could just craft up my own proxy, which I did.&amp;nbsp; After all, no one else is going to consume the service but my own code.&amp;nbsp; In fact, all the code is in a dll called RemoteMouse, which is shared by the XBAP gadget project and the application.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;One area that was a little tricky was protecting both the gadget and the application for the possbility that one would not be alive.&amp;nbsp; I achieved this by instantiating the client proxy on a seperate thread.&amp;nbsp; If I get an exception from the server -- which would most likely occur if the gadget wasn't launched or the application wasn't launched -- I brute force null out the client and create a new one in a do/while loop every second.&amp;nbsp; This might sound expensive, but turns out not to be. I found this approach easier than handling lots of events within WCF around the CommunicationState enumeration.&amp;nbsp; One thing I don't do is nicely disconnect from the server, which I should do.&lt;/P&gt;
&lt;P&gt;The way I host WCF within WPF is based on a sample in the SDK in the Cross Technology Samples/Integration Samples for the .NET Framework 3.0 Features called Hosting A WCF Service in WPF.&amp;nbsp; It turns out to be pretty simple and elegant.&amp;nbsp; I have an interface called IDisplay, which is implemented by the Trackball control. Then, when I create the WCF service, I pass a reference to the trackball class to the service in the constructor to the service. I can then call methods on the trackball from the WCF service. Pretty nifty!&lt;/P&gt;
&lt;P&gt;To install, double click the RemoteMouse.gadget file. Then, compile the cubeapp_exe solution.&amp;nbsp; If you don't have VS installed on Vista, no problem. Just use the trick &lt;A class="" href="http://blogs.msdn.com/tims/archive/2006/04/05/569504.aspx" mce_href="http://blogs.msdn.com/tims/archive/2006/04/05/569504.aspx"&gt;Tim Sneath&lt;/A&gt;&amp;nbsp;outlines here, as every build of Vista has all the tools needed to compile .NET 3.0 apps.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A class="" href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip" mce_href="http://winfx.members.winisp.net/files/wpf_wcf_gadgets.zip"&gt;Download the code and gadgets.&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=851106" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/karstenj/archive/tags/Windows+Presentation+Foundation+_2800_Avalon_2900_/default.aspx">Windows Presentation Foundation (Avalon)</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/Vista/default.aspx">Vista</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/Windows+Communication+Foundation/default.aspx">Windows Communication Foundation</category><category domain="http://blogs.msdn.com/karstenj/archive/tags/WCF/default.aspx">WCF</category></item></channel></rss>