<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wheel &#187; client</title>
	<atom:link href="http://wheel.troxo.com/tag/client/feed/" rel="self" type="application/rss+xml" />
	<link>http://wheel.troxo.com</link>
	<description>The official blog of Troxo</description>
	<lastBuildDate>Mon, 11 Jan 2010 07:45:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>On .NET Remoting</title>
		<link>http://wheel.troxo.com/2007/08/13/on-net-remoting/</link>
		<comments>http://wheel.troxo.com/2007/08/13/on-net-remoting/#comments</comments>
		<pubDate>Mon, 13 Aug 2007 11:00:48 +0000</pubDate>
		<dc:creator>Mladen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[troxo]]></category>
<category>.net</category><category>client</category><category>server</category><category>troxo</category>
		<guid isPermaLink="false">http://www7.troxo.com/2007/08/13/on-net-remoting/</guid>
		<description><![CDATA[Recently we had a .NET based project where we had to enable simple client to server communication. We needed a fast solution, totally embedded into applications (meaning &#8211; no IIS web services were allowed, unfortunately).
Basically, the challenge was: the main application has to provide remote access to its dynamically created objects, like in the image [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we had a .NET based project where we had to enable simple client to server communication. We needed a fast solution, totally embedded into applications (meaning &#8211; no IIS web services were allowed, unfortunately).</p>
<p>Basically, the challenge was: the main application has to provide remote access to its dynamically created objects, like in the image bellow:</p>
<p><img src="http://wheel.troxo.com/wp-content/uploads/2007/07/remoting_chalenge.png" alt="Remoting Project Challenge" /></p>
<p>We found some really good articles on the net like <a href="http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=62">Remoting in C#</a> and <a href="http://www.csharphelp.com/archives/archive187.html">Remoting and Distributed Computing in C#</a>, but none explaining everything we needed &#8211; so after some digging into the MSDN, here is the solution.</p>
<p>&quot;Single call&quot; remoting creates a new remoting object for every call by the client. &quot;Singleton&quot; reuses the same object for every client&#8217;s call.</p>
<p>&quot;Single call&quot; remoting was not fitting our problem because we needed just one proxy object which will forward calls to internal objects.</p>
<p>In our project there was a small catch with the use of &quot;Singleton&quot;. Basically, if you do not create an object before the first call from the client, the object will be created automatically (with the first client&#8217;s call), leaving it unbound to our server objects (in the image above that would mean that &quot;remoting facade&quot; does not have references to internal objects &#8211; Object 1, Object 2, etc.).</p>
<p>The solution is to create a remoting object, initialize it with references to local objects and use <code>RemotingServices.Marshal</code> method to bind the remoting object instance with the remoting service (like in the following example from the attached project):</p>
<pre class="csharpcode">
Logics.Counter counter = <span class="kwrd">new</span> Logics.Counter();
Logics.RemoteCounter remotingCounter = <span class="kwrd">new</span> Logics.RemoteCounter();
<span class="rem">//initialize remoting object with the reference to local object</span>
remotingCounter.SetLocalCounter(counter);
<span class="rem">//select channel to communicate</span>
TcpChannel channel = <span class="kwrd">new</span> TcpChannel(8085);
ChannelServices.RegisterChannel(channel, <span class="kwrd">false</span>); <span class="rem">//register channel</span>
<span class="rem">//register remoting service</span>
RemotingConfiguration.RegisterWellKnownServiceType(<span class="kwrd">typeof</span>(Logics.RemoteCounter), <span class="str">"RemoteCounter"</span>, WellKnownObjectMode.Singleton);
<span class="rem">//bind remoting object with remoting service</span>
RemotingServices.Marshal(remotingCounter, <span class="str">"RemoteCounter"</span>);</pre>
<p>The complete sample: <a href="http://wheel.troxo.com/wp-content/uploads/2007/07/troxosamplesremoting.zip" title="troxosamplesremoting.zip">troxosamplesremoting.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wheel.troxo.com/2007/08/13/on-net-remoting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

