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(); }
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; }