Exemple #1
0
        static void Main(string[] args)
        {
            Console.Write("Enter the name of the user you want to connect with: ");
            string serviceUserName = Console.ReadLine();

            Uri serviceUri = new Uri(String.Format("sb://{0}/services/{1}/EchoService/", ServiceBusEnvironment.DefaultRelayHostName, serviceUserName));

            EndpointAddress address = new EndpointAddress(serviceUri);

            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>("RelayEndpoint", address);
            IEchoChannel channel = channelFactory.CreateChannel();

            channel.Open();

            Console.WriteLine("Enter text to echo (or [Enter] to exit):");
            string input = Console.ReadLine();

            while (!String.IsNullOrEmpty(input))
            {
                try
                {
                    Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
                input = Console.ReadLine();
            }

            channel.Close();
            channelFactory.Close();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.Write("Your Service Namespace: ");
            string serviceNamespace = Console.ReadLine();

            Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("http", serviceNamespace, "HttpEchoService");

            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>("ServiceBusEndpoint", new EndpointAddress(serviceUri));

            IEchoChannel channel = channelFactory.CreateChannel();

            channel.Open();


            Console.WriteLine("Enter text to echo (or [Enter] to exit):");
            string input = Console.ReadLine();

            while (input != String.Empty)
            {
                try
                {
                    Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
                input = Console.ReadLine();
            }

            channel.Close();
            channelFactory.Close();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;

            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>("RelayEndpoint");
            IEchoChannel channel = channelFactory.CreateChannel();

            channel.Open();

            Console.WriteLine("Enter text to echo (or [Enter] to exit):");
            string input = Console.ReadLine();

            while (input != string.Empty)
            {
                try
                {
                    Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
                input = Console.ReadLine();
            }

            channel.Close();
            channelFactory.Close();
        }
Exemple #4
0
        public async Task Run(string httpAddress, string sendToken)
        {
            var channelFactory =
                new ChannelFactory <IEchoChannel>("ServiceBusEndpoint", new EndpointAddress(httpAddress));

            channelFactory.Endpoint.Behaviors.Add(
                new TransportClientEndpointBehavior(TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken)));

            using (IEchoChannel channel = channelFactory.CreateChannel())
            {
                Console.WriteLine("Enter text to echo (or [Enter] to exit):");
                string input = Console.ReadLine();
                while (input != string.Empty)
                {
                    try
                    {
                        Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error: " + e.Message);
                    }
                    input = Console.ReadLine();
                }
                channel.Close();
            }
            channelFactory.Close();
        }
        static void Main(string[] args)
        {
            // Determine the system connectivity mode based on the command line
            // arguments: -http, -tcp or -auto  (defaults to auto)
            ServiceBusEnvironment.SystemConnectivity.Mode = GetConnectivityMode(args);

            Console.Write("Your Service Namespace: ");
            string serviceNamespace = Console.ReadLine();

            Console.Write("Your Issuer Name: ");
            string issuerName = Console.ReadLine();

            Console.Write("Your Issuer Secret: ");
            string issuerSecret = Console.ReadLine();

            // create the service URI based on the service namespace
            Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "EchoService");

            // create the credentials object for the endpoint
            TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();

            sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret);

            // create the channel factory loading the configuration
            BalancingChannelFactory <IEchoChannel> channelFactory = new BalancingChannelFactory <IEchoChannel>(new NetTcpRelayBinding(EndToEndSecurityMode.None, RelayClientAuthenticationType.RelayAccessToken), new EndpointAddress(serviceUri));

            // apply the Service Bus credentials
            channelFactory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);


            Console.WriteLine("Enter text to echo (or [Enter] to exit):");
            string input = Console.ReadLine();

            while (input != String.Empty)
            {
                IEchoChannel channel = channelFactory.CreateChannel();
                channel.Open();

                try
                {
                    // create and open the client channel
                    Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                    channel.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                    channel.Abort();
                }


                input = Console.ReadLine();
            }

            channelFactory.Close();
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            lbStatus.Items.Clear();
            Application.DoEvents();

            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;

            var serviceNamespace = "msswit2013relay";
            var issuerName       = "owner";
            var issuerSecret     = "IqyIwa7gNjBO89HT+3Vd1CcoBbyibvcv6Hd92J+FtPg=";

            Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "Service");

            TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();

            sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret);

            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>("RelayEndpoint", new EndpointAddress(serviceUri));

            channelFactory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);

            IEchoChannel channel = channelFactory.CreateChannel();

            channel.Open();

            lbStatus.Items.Add("---");
            lbStatus.Items.Add("test: Ping");
            Application.DoEvents();

            lbStatus.Items.Add("result: " + channel.Ping());
            Application.DoEvents();

            lbStatus.Items.Add("---");
            lbStatus.Items.Add("test: Echo");
            Application.DoEvents();

            lbStatus.Items.Add("echo login: "******"echo pass: "******"---");
            lbStatus.Items.Add("test: IsLoginSuccess");
            lbStatus.Items.Add("login: "******"pass: "******"result: " + channel.IsLoginSuccess(tbLogin.Text, tbPass.Text));
            lbStatus.Items.Add("---");
            Application.DoEvents();

            channel.Close();
            channelFactory.Close();
        }
Exemple #7
0
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;

            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>("RelayEndpoint");
            IEchoChannel channel = channelFactory.CreateChannel();

            channel.Open();

            channel.Echo("1231321312");

            return(View());
        }
        static void Main(string[] args)
        {
            Console.Write("Your Service Namespace: ");
            string serviceNamespace = Console.ReadLine();

            Console.Write("Your Issuer Name: ");
            string issuerName = Console.ReadLine();

            Console.Write("Your Issuer Secret: ");
            string issuerSecret = Console.ReadLine();

            Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "SimpleWebTokenAuthenticationService");

            TransportClientEndpointBehavior behavior = new TransportClientEndpointBehavior();

            behavior.TokenProvider = TokenProvider.CreateSimpleWebTokenProvider(
                ComputeSimpleWebTokenString(issuerName, issuerSecret));

            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>("RelayEndpoint", new EndpointAddress(serviceUri));

            channelFactory.Endpoint.Behaviors.Add(behavior);

            IEchoChannel channel = channelFactory.CreateChannel();

            channel.Open();

            Console.WriteLine("Enter text to echo (or [Enter] to exit):");
            string input = Console.ReadLine();

            while (input != String.Empty)
            {
                try
                {
                    Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
                input = Console.ReadLine();
            }

            channel.Close();
            channelFactory.Close();
        }
        protected void sendButton_Click(object sender, EventArgs e)
        {
            ChannelFactory <IEchoChannel> channelFactory = null;
            IEchoChannel channel = null;

            try
            {
                //Create a Behavior for the Credentials
                TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();
                sharedSecretServiceBusCredential.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret);

                //Create a Channel Factory
                channelFactory = new ChannelFactory <IEchoChannel>(new NetTcpRelayBinding(), new EndpointAddress(serviceAddress));
                channelFactory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);

                LogMessage("Opening channel to: {0}", serviceAddress);
                channel = channelFactory.CreateChannel();
                channel.Open();

                LogMessage("Sending: {0}", echoTextBox.Text);
                string echoedText = channel.Echo(echoTextBox.Text);
                LogMessage("Received: {0}", echoedText);
                echoTextBox.Text = string.Empty;

                LogMessage("Closing channel");
                channel.Close();
                LogMessage("Closing factory");
                channelFactory.Close();
            }
            catch (Exception ex)
            {
                LogMessage("Error sending: {0}<br/>{1}", ex.Message, ex.StackTrace.Replace("\n", "<br/>"));

                // Close the channel and factory properly
                if (channel != null)
                {
                    CloseCommunicationObject(channel);
                }
                if (channelFactory != null)
                {
                    CloseCommunicationObject(channelFactory);
                }
            }
        }
        static void Main(string[] args)
        {
            Console.Write("Enter the Service Namespace you want to connect to: ");
            string serviceNamespace = Console.ReadLine();

            Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "EchoService");

            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>("RelayEndpoint", new EndpointAddress(serviceUri, EndpointIdentity.CreateDnsIdentity("localhost")));

            channelFactory.Credentials.UserName.UserName = "******";
            channelFactory.Credentials.UserName.Password = "******";

            IEchoChannel channel = channelFactory.CreateChannel();

            try
            {
                channel.Open();


                Console.Write("Enter the text to echo (or press [Enter] to exit): ");
                string input = Console.ReadLine();
                while (input != String.Empty)
                {
                    try
                    {
                        Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error: " + e.Message);
                    }
                    input = Console.ReadLine();
                }

                channel.Close();
            }
            finally
            {
                channel.Abort();
            }
            channelFactory.Close();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            Console.Write("Your Service Namespace: ");
            string serviceNamespace = Console.ReadLine();

            Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("https", serviceNamespace, "EchoService");

            // explicitly setting the endpoint to entity to "localhost" to match the sample certificate
            ChannelFactory <IEchoChannel> channelFactory = new ChannelFactory <IEchoChannel>(
                "ServiceBusEndpoint",
                new EndpointAddress(serviceUri, EndpointIdentity.CreateDnsIdentity("localhost")));

            IEchoChannel channel = channelFactory.CreateChannel();

            channel.Open();


            Console.WriteLine("Enter text to echo (or [Enter] to exit):");
            string input = Console.ReadLine();

            while (input != String.Empty)
            {
                try
                {
                    Console.WriteLine("Server echoed: {0}", channel.Echo(input));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
                input = Console.ReadLine();
            }

            channel.Close();
            channelFactory.Close();
        }