Testament service

The Testament feature is supported.

This feature allows a client to request the router to publish some predefined events when the client disconnects.

Enabling the testament service on the router-side

In order to enable it from router-side, call HostTestamentService extension method of the relevant realm (this is similiar to the Router-side meta-api usage):

DefaultWampHost host = new DefaultWampHost("ws://");

IWampHostedRealm realm = host.RealmContainer.GetRealmByName("realm1");

IDisposable disposable = realm.HostTestamentService();

// Uncomment to unregister the Testament service. 
// disposable.Dispose(); 


Consuming the testament service

In order to consume the Testament service, one can define its contract and consume it using the CalleeProxy method. Another option is to use the GetTestamentServiceProxy extension method of IWampRealmProxy which returns such a proxy:

private static async Task Run()
    WampChannelFactory channelFactory = new WampChannelFactory();

    IWampChannel channel =

    long? sessionId = null;

    channel.RealmProxy.Monitor.ConnectionEstablished += (sender, args) => { sessionId = args.SessionId; }; 

    await channel.Open().ConfigureAwait(false);

    IWampTestamentServiceProxy proxy = channel.RealmProxy.GetTestamentServiceProxy();

    string testamentTopic = "com.example.testament";

    for (int i = 0; i < 5; ++i)
        object[] testamentArgs = new object[] {"this is my testament!"};

        Dictionary<string, object> testamentKwArgs =
            new Dictionary<string, object> {{"foo", i}, {"bar", "baz"}, {"sess", sessionId}};

            await proxy.AddTestamentAsync(testamentTopic, testamentArgs, testamentKwArgs)

            Console.WriteLine("testament added");
        catch (Exception ex)
            Console.WriteLine("adding testament failed! " + ex);

    Console.WriteLine(@"Press any key to close channel. 5 events should be published to ""com.example.testament""");

This sample is based on this Crossbar example.