Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Making BERT RPC calls in C#

theburningmonk edited this page Nov 13, 2012 · 4 revisions

The full example is available in the C# example project here.

For more information regarding how BERT-RPC works, please refer to the BERT-RPC spec.

Getting Started

Before you can make BERT-RPC calls against a BERT-RPC server, you first need to create an instance of Filbert.Rpc.BertRpcClient using the static Start method:

var client = Filbert.Rpc.BertRpcClient.Start(serviceUrl, portNumber)

RPC Client - Call (synchronous request)

Once you have a client, use BertRpcClient.CallAsTask to make a synchronous call against a BERT-RPC server, this will return an instance of Task<Bert> which you can then use to get the response from the server.

Suppose there is a nat Erlang module running on the BERT-RPC server, which looks like this:

-module(nat).
-export([add/2, die/1]).

add(A, B) -> A + B.

die(X) -> X = 10.

To call nat.add(1, 100) and wait for the response synchronously, this is all you need to do:

var result = client.CallAsTask("nat", "add", Bert.NewInteger(1), Bert.NewInteger(100))
                   .Result;

RPC Client - Cast (fire-and-forget request)

To make a cast call against a BERT-RPC server and wait for the acknowledgement synchronously:

client.CastAsTask("nat", "die", Bert.NewInteger(666)).Wait();

C# 5 asynchrony

I decided to expose the xxxAsTask methods in hope that it's async ready in C# 5, but haven't got around to testing this very much at the time of this writing.

If you run into any problems/inconvenience using the RPC client within C# 5, please free feel to contact me and I'll do my best to resolve any issues you come across as soon as I can!