static void Main()
{
// Set some global variables.
string channelName = "StoreandFowardMessageHelloWorld";
string serverAddress = "ServerMailAddress@fabrikam.com";
string serverPWD = "MyPassword";
string clientAddress = "DeviceMailAddress@fabrikam.com";
string exchangeServerLocation = "http://fabrikam";
// Create the listener. If you are using Windows credentials,
// pass a null value as the second argument to the ExchangeWebServiceMailBinding.
MailBindingBase 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, serverAddress), parameters);
listener.Open();
IInputChannel inputChannel = listener.AcceptChannel();
inputChannel.Open();
Message reply = inputChannel.Receive();
CFMessagingSerializer serializer = new CFMessagingSerializer(typeof(string));
string str = "";
str = reply.GetBody<string>(serializer);
// Process the message.
str += ", World!";
// Send the response through an output channel.
Message m = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "urn:test", str, serializer);
IChannelFactory<IOutputChannel> channelFactory = binding.BuildChannelFactory<IOutputChannel>(parameters);
channelFactory.Open();
IOutputChannel outChannel = channelFactory.CreateChannel(new EndpointAddress(
MailUriHelper.CreateUri(channelName, clientAddress)));
outChannel.Open();
outChannel.Send(m);
// Clean up.
outChannel.Close();
channelFactory.Close();
listener.Close();
inputChannel.Close();
binding.Close();
}