Ayende @ Rahien

Unnatural acts on source code

NIH alert! Writing my own RPC systems

Let us see if you can help me here, I found myself facing a rather unpleasant realization, in that I need to communicate between two processes (that compose a single system) with some rather draconian measures about how they are going to be used.

Quite simply, I need to expose an interface with ~25 methods on it to the second process. So far, it is pretty easy to do, right?

The problem is that the first process is a standard .NET executable, which may also be run on the Mono platform while the second is a Silverlight application. My first thought, just use remoting to handle this, failed because remoting isn’t available to Silverlight. My second thought, to use WCF, failed because that isn’t available on Mono.

Building a simple RPC system is pretty easy, so that doesn’t worry me. The reason I am reluctant to do so is that I really don’t want to build yet another infrastructure. At some point, even to me, NIH flag starts to pop up.

Tags:

Posted By: Ayende Rahien

Published at

Originally posted at

Comments

Marc Gravell
01/06/2010 10:11 AM by
Marc Gravell

Can you pick the Mono version? 2.6 has the WCF stack from Silverlight, IIRC.

Ayende Rahien
01/06/2010 10:31 AM by
Ayende Rahien

And that is why I love this blog :-)

Thanks, I'll check this out

RichB
01/06/2010 10:54 AM by
RichB

I thought you used ProtocolBuffers in UberProf - can you use that to send messages between processes instead of RPC?

Davy Brion
01/06/2010 10:54 AM by
Davy Brion

well, the simplest way to do this if you can use the mono version with WCF support is Agatha :)

Ayende Rahien
01/06/2010 10:56 AM by
Ayende Rahien

Rich,

I am using it there, but I use it as data stream, not RPC.

For RPC, you would need to handle a lot of things, such as error handling, method invocation, etc.

Marc Gravell
01/06/2010 11:13 AM by
Marc Gravell

Re the protocol buffers / RPC discussion; protobuf-net has a basic RPC stack built in using HTTP, covering those error-handling, method-invocation, etc issues. I honestly haven't tried it between Silverlight and Mono, so I can't guarantee that it'll work. If you're on a framework with Expression, it allows usage like:

var result = proxy.Invoke(svc => svc.SomeMethod("abc", someArg, obj.SomeValue));

Without Expression it is a bit less pretty.

Demis Bellot
01/06/2010 11:35 AM by
Demis Bellot

Sounds like a good spot for a plug.

You can use Service Stack ( http://www.servicestack.net) - an opensource XML/JSON/REST web services framework that runs on .NET or Mono which can be hosted in IIS, XSP or even inside a standalone console app (which uses HttpListener behind the scenes).

This link below shows a live 'silverlight client' talking to XML services hosted on CentOS/Nginx server:

www.servicestack.net/.../Silverlight.htm

For a quick overview on servicestack here's an in-depth tutorial creating and calling mono webservices from a MonoTouch client (C# on iPhone):

http://www.servicestack.net/monotouch/remote-info/

Ayende Rahien
01/06/2010 12:14 PM by
Ayende Rahien

Dennis,

I'll look at that. My issue with HttpListener is that it requires admin privileges

Ayende Rahien
01/06/2010 12:14 PM by
Ayende Rahien

Marc,

What implementation are you talking about?

Ayende Rahien
01/06/2010 12:17 PM by
Ayende Rahien

On second thought, Demis, I checked out the license, and it is GPL, which mean that I pretty much can't make any use of it

Demis Bellot
01/06/2010 01:08 PM by
Demis Bellot

@Ayende

Yeah admin rights is a problem with HttpListener. This is where the other options may be more appropriate. On the upside HttpListener allows you to host on the same port at the same time with IIS.

Just sent you an email - I'm happy to change it to a more appropriate licence if needed.

Marc Gravell
01/06/2010 01:08 PM by
Marc Gravell

@Ayende - I don't fully understand the question, but note that the current server implementation uses HttpListener, so if that is a problem... But I'm on about the RPC stack in protobuf-net; examples are in the unit-test project - see the HttpWithLambda test-fixture here: code.google.com/.../HttpBasic.cs

Ayende Rahien
01/06/2010 01:16 PM by
Ayende Rahien

Marc,

I need to run it as non admin user

Marc Gravell
01/06/2010 01:20 PM by
Marc Gravell

Is the Mono server on linux? On Windows you don't actually need to be admin to use HttpListener - you just need the port opened for http.sys (via netsh etc). Is there maybe something similar for linux?

Ayende Rahien
01/06/2010 01:26 PM by
Ayende Rahien

Marc,

I know, but that step is an extra one that I really don't want to do

Tiz Zaqyah
01/06/2010 03:34 PM by
Tiz Zaqyah

Ayende,

I am a little bit confused here. What do you mean but the extra one step that you are talking about. I thought it just be same for both?

Ayende Rahien
01/06/2010 06:16 PM by
Ayende Rahien

I mean that it is an extra step in the install process

Jeff Brown
01/06/2010 07:38 PM by
Jeff Brown

Have you looked at Thrift?

Steve Wagner
01/07/2010 08:54 AM by
Steve Wagner

Why you dont create a simple ProtocolBuffers based message bus and send messages over it instead of doing RPC?

Ayende Rahien
01/07/2010 09:04 AM by
Ayende Rahien

Steve,

I need request / reply, not pub/sub

Steve Wagner
01/07/2010 09:21 AM by
Steve Wagner

But you could block the execution until a reply message was received.

Ayende Rahien
01/07/2010 09:22 AM by
Ayende Rahien

So I am building RPC on top of pub/sub?

What does this give me?

Steve Wagner
01/07/2010 09:27 AM by
Steve Wagner

It solves you problem without needing to have an external technology which is may not implemented in another platform. It also could work if java is on one of both sides.

Ayende Rahien
01/07/2010 09:28 AM by
Ayende Rahien

The actual serialization format isn't what worries me.

Felix
01/07/2010 08:36 PM by
Felix

@Frans,

Thanks you for defining someone a "daredevil", it makes me feel younger. Less polite is the "big mounth",but I know, is the price we have to pay for you sharing your wisdom. but is Actually the 'personal' contrib version i'm talking about is on the offical contrib version. I do not have so much useless time to spent, this is the reason my work is for sure a little monkey in comparison to your. I just did it cause NH give me a lot of productivity and I would like to pay back something. Basically I'm really surprised on seeing so many people complaining for documentation, the site NHForge is plain of whatever you need to starup with NH. Plus you have the source code. Plus you have a lot of people helping you basically for free ( Fabio Maulo one of the best,Ayende as well). Furthermore, the fancy designer with fancy colored boxes is a "must have" that fail as soon the model pass the 15 entities...

Mike McG
01/10/2010 03:23 AM by
Mike McG

I'm sure you thought of this, but if you have a moment can you explain why a separate proxy layer/service/wrapper that translates between Remoting and WCF is not a good option?

Ayende Rahien
01/10/2010 06:26 AM by
Ayende Rahien

Because I initially thought that WCF is completely not an option

Guillaume
01/11/2010 08:58 PM by
Guillaume

Have you considered using some RESTful services ? (I'm not sure of ASP.Net MVC's compatibility with Mono but it could be a good start)

You may also find some interesting keys with json services (with JSON.Net for example)

Comments have been closed on this topic.