public static TProxy GetCalleeProxyPortable <TProxy>(this IWampRealmServiceProvider provider, ICalleeProxyInterceptor interceptor) where TProxy : class
        {
#if !PCL
            return(provider.GetCalleeProxy <TProxy>(interceptor));
#else
            try
            {
                return(provider.GetCalleeProxy <TProxy>(interceptor));
            }
            catch (NotSupportedException ex)
            {
                GeneratedCodeException exception =
                    ex.InnerException as GeneratedCodeException;

                var code = exception.GeneratedCode;

                Type instanceType =
                    GetInstanceType <TProxy>(code);

                MethodInfo methodToInvoke =
                    typeof(IWampRealmServiceProvider)
                    .GetMethods()
                    .FirstOrDefault(x => x.Name == "GetCalleeProxy" &&
                                    x.GetParameters().Any());

                TProxy result =
                    methodToInvoke.MakeGenericMethod(instanceType)
                    .Invoke(provider, new object[] { interceptor }) as TProxy;

                return(result);
            }
#endif
        }
Пример #2
0
        private static void Arguments(IWampRealmServiceProvider serviceProvider)
        {
            IArgumentsService proxy = serviceProvider.GetCalleeProxy <IArgumentsService>();

            proxy.Ping();
            Console.WriteLine("Pinged!");

            int result = proxy.Add2(2, 3);

            Console.WriteLine("Add2: {0}", result);

            var starred = proxy.Stars();

            Console.WriteLine("Starred 1: {0}", starred);

            starred = proxy.Stars(nick: "Homer");
            Console.WriteLine("Starred 2: {0}", starred);

            starred = proxy.Stars(stars: 5);
            Console.WriteLine("Starred 3: {0}", starred);

            starred = proxy.Stars(nick: "Homer", stars: 5);
            Console.WriteLine("Starred 4: {0}", starred);

            string[] orders = proxy.Orders("coffee");
            Console.WriteLine("Orders 1: {0}", string.Join(", ", orders));

            orders = proxy.Orders("coffee", limit: 10);
            Console.WriteLine("Orders 2: {0}", string.Join(", ", orders));
        }
Пример #3
0
        private static void Complex(IWampRealmServiceProvider serviceProvider)
        {
            IComplexResultService proxy =
                serviceProvider.GetCalleeProxy <IComplexResultService>();

            string[] splitted = proxy.SplitName("George Bush");
            Console.WriteLine("Pinged!");
        }
Пример #4
0
        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);
            }
        }
        private async static Task Run(string wsuri, string realm)
        {
            Console.WriteLine("Connecting to {0}, realm {1}", wsuri, realm);

            DefaultWampChannelFactory factory = new DefaultWampChannelFactory();

            IWampChannel channel =
                factory.CreateJsonChannel(wsuri, realm);

            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
            ISubject <string> helloSubject =
                services.GetSubject <string>("com.example.onhello");

            IDisposable subscription =
                helloSubject.Subscribe
                    (x => Console.WriteLine("event for 'onhello' received: {0}", x));

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


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

            await services.RegisterCallee(callee)
            .ConfigureAwait(false);

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


            // PUBLISH and CALL every second... forever
            ISubject <int> onCounterSubject =
                services.GetSubject <int>("com.example.oncounter");

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

            int counter = 0;

            while (true)
            {
                // PUBLISH an event
                onCounterSubject.OnNext(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);
            }
        }