示例#1
0
        public async Task Run(string listenAddress, string listenToken)
        {
            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect; // Auto-detect, default
            //ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https; // HTTPS WebSockets

            var controller = new RelayServiceHostController(() =>
            {
                ServiceHost host = new ServiceHost(this);
                host.AddServiceEndpoint(
                    GetType(),
                    new NetTcpRelayBinding {
                    IsDynamic = false
                },
                    listenAddress)
                .EndpointBehaviors.Add(
                    new TransportClientEndpointBehavior(
                        TokenProvider.CreateSharedAccessSignatureTokenProvider(listenToken)));
                return(host);
            });

            controller.Open();
            Console.WriteLine("Service listening at address {0}", listenAddress);
            Console.WriteLine("Press [Enter] to close the listener and exit.");
            Console.ReadLine();
            controller.Close();
        }
        public async Task Run(string listenAddress, string listenToken)
        {
            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect; // Auto-detect, default
            //ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https; // HTTPS WebSockets

            var controller = new RelayServiceHostController(() =>
            {
                ServiceHost host = new ServiceHost(this);
                host.AddServiceEndpoint(
                    GetType(),
                    new NetTcpRelayBinding {IsDynamic = false},
                    listenAddress)
                    .EndpointBehaviors.Add(
                        new TransportClientEndpointBehavior(
                            TokenProvider.CreateSharedAccessSignatureTokenProvider(listenToken)));
                return host;
            });
            controller.Open();
            Console.WriteLine("Service listening at address {0}", listenAddress);
            Console.WriteLine("Press [Enter] to close the listener and exit.");
            Console.ReadLine();
            controller.Close();
            
        }