public static void StartListener(this SubscriptionClient subscriptionClient, object singletonInstance, ReceiveMode receiveMode = ReceiveMode.PeekLock, bool requiresSession = false)
        {
            Uri address = new Uri(subscriptionClient.MessagingFactory.Address, subscriptionClient.TopicPath + "/Subscriptions/" + subscriptionClient.Name);
            BrokeredServiceHost host = new BrokeredServiceHost(singletonInstance, address, subscriptionClient.MessagingFactory.GetSettings().TokenProvider, receiveMode, requiresSession);

            registeredSubscriptionHosts.Add(subscriptionClient, host);
            host.Open();
        }
        public static void StartListener(this QueueClient queueClient, object singletonInstance, ReceiveMode receiveMode = ReceiveMode.PeekLock, bool requiresSession = false)
        {
            Uri address = new Uri(queueClient.MessagingFactory.Address, queueClient.Path);
            BrokeredServiceHost host = new BrokeredServiceHost(singletonInstance, address, queueClient.MessagingFactory.GetSettings().TokenProvider, receiveMode, requiresSession);

            registeredQueueHosts.Add(queueClient, host);
            host.Open();
        }
        public static void StartListener(this SubscriptionClient subscriptionClient, object singletonInstance, ReceiveMode receiveMode = ReceiveMode.PeekLock, bool requiresSession = false)
        {
            Uri address = new Uri(subscriptionClient.MessagingFactory.Address, subscriptionClient.TopicPath + "/Subscriptions/" + subscriptionClient.Name);
            BrokeredServiceHost host = new BrokeredServiceHost(singletonInstance, address, subscriptionClient.MessagingFactory.GetSettings().TokenProvider, receiveMode, requiresSession);

            registeredSubscriptionHosts.Add(subscriptionClient, host);
            host.Open();
        }
        public static void StartListener(this QueueClient queueClient, object singletonInstance, ReceiveMode receiveMode = ReceiveMode.PeekLock, bool requiresSession = false)
        {
            Uri address = new Uri(queueClient.MessagingFactory.Address, queueClient.Path);
            BrokeredServiceHost host = new BrokeredServiceHost(singletonInstance, address, queueClient.MessagingFactory.GetSettings().TokenProvider, receiveMode, requiresSession);

            registeredQueueHosts.Add(queueClient, host);
            host.Open();
        }
        void SetErrorHandler(ChannelDispatcher channelDispatcher, Type serviceType)
        {
            MethodInfo onErrorMethod = BrokeredServiceHost.FindConventionOrUniqueMatchingMethod(serviceType, "OnError", new HashSet <Type>()
            {
                typeof(void)
            }, typeof(Exception));

            if (onErrorMethod != null)
            {
                channelDispatcher.ErrorHandlers.Add(new InvokeMethodErrorHandler(onErrorMethod));
            }
        }