Exemplo n.º 1
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            // Creating the message to send
            TransmittedObject to = new TransmittedObject();

            to.str = "Hello";
            to.i   = 5;

            XmlSerializerWrapper wrapper =
                new XmlSerializerWrapper(typeof(TransmittedObject));

            Message m = Message.CreateMessage
                            (MessageVersion.Soap11, "urn:test", to, wrapper);

            // Creating the channel to send the message
            BasicHttpBinding           binding    = new BasicHttpBinding();
            BindingParameterCollection parameters =
                new BindingParameterCollection();
            IChannelFactory <IRequestChannel> channelFactory =
                binding.BuildChannelFactory <IRequestChannel>(parameters);

            channelFactory.Open();

            // Opening the channel
            IRequestChannel outChannel =
                channelFactory.CreateChannel
                    (new EndpointAddress
                        (new Uri("http://<<ServerAddress>>:<<PortNumber>>")));

            outChannel.Open(TimeSpan.MaxValue);

            // Sending the Message and waiting for the reply
            Message reply = outChannel.Request(m, TimeSpan.MaxValue);

            // Deserializing and using the Message
            TransmittedObject to1 =
                reply.GetBody <TransmittedObject>
                    (new XmlSerializerWrapper(typeof(TransmittedObject)));

            MessageBox.Show(to1.str + " " + to1.i.ToString());

            // Cleaning up
            outChannel.Close();
            channelFactory.Close();

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Creating the Binding
            BasicHttpBinding binding = new BasicHttpBinding();

            BindingParameterCollection parameters =
                new BindingParameterCollection();

            IChannelListener <IReplyChannel> listener =
                binding.BuildChannelListener <IReplyChannel>
                    (new Uri("http://<<ServerAddress>>:<<PortNumber>>"),
                    parameters);

            listener.Open();

            XmlSerializerWrapper wrapper =
                new XmlSerializerWrapper(typeof(TransmittedObject));

            // Opening the Channel
            IReplyChannel channel = listener.AcceptChannel();

            channel.Open(TimeSpan.MaxValue);

            // Waiting for and receiving the Message
            RequestContext r =
                channel.ReceiveRequest(TimeSpan.MaxValue);

            TransmittedObject to =
                r.RequestMessage.GetBody <TransmittedObject>(wrapper);

            // Processing the Message
            to.str = to.str + " World";
            to.i   = to.i + 1;

            // Creating the return Message
            Message m = Message.CreateMessage
                            (MessageVersion.Soap11, "urn:test", to, wrapper);

            r.Reply(m, TimeSpan.MaxValue);

            // Cleaning up
            channel.Close();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // Creating the Channel
            string channelName = "EMailHelloWorld";

            string serverAddress          = "*****@*****.**";
            string serverPWD              = "MyPassword";
            string clientAddress          = "*****@*****.**";
            string exchangeServerLocation = "http://example.com";

            ExchangeWebServiceMailBinding binding =
                new ExchangeWebServiceMailBinding(
                    new Uri(exchangeServerLocation),
                    new System.Net.NetworkCredential(serverAddress,
                                                     serverPWD));
            BindingParameterCollection parameters =
                new BindingParameterCollection();

            IChannelListener <IInputChannel> listener =
                binding.BuildChannelListener <IInputChannel>
                    (MailUriHelper.CreateUri(channelName, ""), parameters);

            listener.Open();

            // Opening the Channel
            IInputChannel inputChannel = listener.AcceptChannel();

            inputChannel.Open(TimeSpan.MaxValue);
            Console.WriteLine("Channel Open");

            // Waiting and receiving the Message
            Message reply = inputChannel.Receive(TimeSpan.MaxValue);

            Console.WriteLine("Message Recieved");
            XmlSerializerWrapper wrapper = new XmlSerializerWrapper(
                typeof(TransmittedObject));
            TransmittedObject to = reply.GetBody <TransmittedObject>(wrapper);

            // Processing the Message
            to.str = to.str + " World";
            to.i   = to.i + 1;

            Console.WriteLine("Response: " + to.str + " " + to.i.ToString());

            // Creating and returning the Message
            Message m = Message.CreateMessage(binding.MessageVersion,
                                              "urn:test", to, wrapper);

            IChannelFactory <IOutputChannel> channelFactory =
                binding.BuildChannelFactory <IOutputChannel>(parameters);

            channelFactory.Open();

            IOutputChannel outChannel = channelFactory.CreateChannel(
                new EndpointAddress(
                    MailUriHelper.CreateUri(channelName, clientAddress)));

            outChannel.Open();

            Console.WriteLine("Out Channel Open");

            // Sending the Message over the OutChannel
            outChannel.Send(m);

            Console.WriteLine("Message Sent");

            // Cleaning up
            outChannel.Close();
            channelFactory.Close();

            listener.Close();
            inputChannel.Close();
            binding.Close();
        }
Exemplo n.º 4
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            // Creating the Message
            TransmittedObject to = new TransmittedObject();

            to.str = "Hello";
            to.i   = 5;

            XmlSerializerWrapper wrapper =
                new XmlSerializerWrapper(typeof(TransmittedObject));

            Message m = Message.CreateMessage
                            (MessageVersion.Default, "urn:test", to, wrapper);

            // Creating the Channel
            string channelName = "EMailHelloWorld";

            string serverAddress = "*****@*****.**";
            string clientAddress = "*****@*****.**";

            WindowsMobileMailBinding   binding    = new WindowsMobileMailBinding();
            BindingParameterCollection parameters =
                new BindingParameterCollection();

            IChannelFactory <IOutputChannel> channelFactory =
                binding.BuildChannelFactory <IOutputChannel>(parameters);

            channelFactory.Open();

            // Opening the Channel
            IOutputChannel outChannel = channelFactory.CreateChannel(
                new EndpointAddress(MailUriHelper.Create
                                        (channelName, serverAddress)));

            outChannel.Open();

            // Sending the Message
            outChannel.Send(m);

            // Listening for the response
            IChannelListener <IInputChannel> listner =
                binding.BuildChannelListener <IInputChannel>
                    (MailUriHelper.CreateUri(channelName, clientAddress),
                    parameters);

            listner.Open();

            IInputChannel inputChannel = listner.AcceptChannel();

            inputChannel.Open();

            Message reply = inputChannel.Receive();

            // Deserializing and using the Message
            TransmittedObject to1 =
                reply.GetBody <TransmittedObject>
                    (new XmlSerializerWrapper(typeof(TransmittedObject)));

            MessageBox.Show(to1.str + " " + to1.i.ToString());

            // Cleaning up
            outChannel.Close();
            channelFactory.Close();

            listner.Close();
            inputChannel.Close();
            binding.Close();

            Cursor.Current = Cursors.Default;
        }