private async static Task Run(string wsuri, string realm)
        {
            Console.WriteLine("Connecting to {0}, realm {1}", wsuri, realm);

            WampChannelFactory factory = new WampChannelFactory();

            IWampChannel channel =
                factory.ConnectToRealm(realm)
                .WebSocketTransport(wsuri)
                .JsonSerialization()
                .Build();

            IWampClientConnectionMonitor monitor = channel.RealmProxy.Monitor;

            monitor.ConnectionBroken += OnClose;
            monitor.ConnectionError  += OnError;

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

            IWampRealmServiceProvider services = channel.RealmProxy.Services;

            // SUBSCRIBE to a topic and receive events
            HelloSubscriber subscriber = new HelloSubscriber();

            IAsyncDisposable subscriptionDisposable =
                await services.RegisterSubscriber(subscriber)
                .ConfigureAwait(false);

            Console.WriteLine("subscribed to topic 'onhello'");

            // REGISTER a procedure for remote calling
            Add2Service callee = new Add2Service();

            IAsyncDisposable registrationDisposable =
                await services.RegisterCallee(callee)
                .ConfigureAwait(false);

            Console.WriteLine("procedure add2() registered");


            // PUBLISH and CALL every second... forever
            CounterPublisher publisher =
                new CounterPublisher();

            IDisposable publisherDisposable =
                channel.RealmProxy.Services.RegisterPublisher(publisher);

            IMul2Service proxy =
                services.GetCalleeProxy <IMul2Service>();

            int counter = 0;

            while (true)
            {
                // PUBLISH an event
                publisher.Publish(counter);
                Console.WriteLine("published to 'oncounter' with counter {0}", counter);
                counter++;


                // CALL a remote procedure
                try
                {
                    int result = await proxy.Multiply(counter, 3)
                                 .ConfigureAwait(false);

                    Console.WriteLine("mul2() called with result: {0}", result);
                }
                catch (WampException ex)
                {
                    if (ex.ErrorUri != "wamp.error.no_such_procedure")
                    {
                        Console.WriteLine("call of mul2() failed: " + ex);
                    }
                }

                await Task.Delay(TimeSpan.FromSeconds(1))
                .ConfigureAwait(false);
            }
        }