Пример #1
0
        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();
        }