dougherty distilled

Bryan Dougherty's thoughts on technology and software development.
in

Pitfalls for Remoting Beginners

I recently decided to use .NET Remoting as part of a solution.  I was new to Remoting, but it was the right fit for the problem at hand. 

I was pleasantly surprised by how easy it was to get the basic Remoting functionality up and running.  The MSDN docs weren’t the clearest, though.  I think this is probably because Remoting on the whole can get very complex.  To get a little more comfortable with it, I created a test app.  I’d be happy to post it if anyone is interested in seeing a basic Remoting sample.  To satisfy some of my own curiosity, I may post comparison performance metrics between Remoting method calls with in a machine and regular intra-process calls. 

Back to the topic at hand: I ran in two pitfalls in working with Remoting.  I thought I’d share them in the hope that it saves other beginners a few lost hours.

Static Method Calls
Simply Stated: They don’t work.  Instead of the method being called on the Remote service, your application will use the in memory reference.  When you think about it, it makes sense.  There is no need to create a proxy since no instantiated object is needed to call the method.  Therefore the call doesn’t get sent out to the other process.

Passing Parameters By Value
The other issue I had was with passing a parameter by value.  I had a method on my Remoting class that took in an object and modified a few properties.  Since it is a reference type, I can just pass it in with out a ref keyword (ByRef in VB) and my method should be able to affect the properties of the object.  Here’s an example of the kind of method I’m talking about.

  public void TestChangingParameterProps(ParameterObject p)
  {
   p.A++
;
   
p.B "set p values " + p.A.ToString();
  
}

It works fine within a process, as we expect.  However, when calling this method via Remoting, the p that you pass in will not be affected.  Again, if you think about it, it makes sense.  Since the whole parameter object is being copied over (by value) to the other process and the changes are being made there, the memory locations of the properties of p can't be affected.

Hope this helps save someone some time and headaches.

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)