Example #1
0
        static void Main(string[] args)
        {
            Console.Write("Your Service Namespace: ");
            string serviceNamespace = Console.ReadLine();

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

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

            IPingContract channel = channelFactory.CreateChannel();

            Console.WriteLine("Opening Channel.");
            channel.Open();

            for (int i = 1; i <= 25; i++)
            {
                Console.WriteLine("Ping: {0}", i);
                channel.Ping(i);
            }

            Console.WriteLine("Closing Channel.");
            channel.Close();

            channelFactory.Close();

            Console.WriteLine("Press [Enter] to exit");
            Console.ReadLine();
        }
        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, "PingService");

            TransportClientEndpointBehavior sharedSecretServiceBusCredential = new TransportClientEndpointBehavior();

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

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

            channelFactory.Endpoint.Behaviors.Add(sharedSecretServiceBusCredential);

            IPingContract channel = channelFactory.CreateChannel();

            Console.WriteLine("Opening Channel.");
            channel.Open();

            for (int i = 1; i <= 25; i++)
            {
                Console.WriteLine("Ping: {0}", i);
                channel.Ping(i);
            }

            Console.WriteLine("Closing Channel.");
            channel.Close();
            channelFactory.Close();

            Console.WriteLine("Press [Enter] to exit.");
            Console.ReadLine();
        }