' Set some global variables.
Dim channelName As String = "StoreandFowardMessageHelloWorld"
Dim serverAddress As String = "ServerMailAddress@fabrikam.com"
Dim serverPWD As String = "MyPassword"
Dim clientAddress As String = "DeviceMailAddress@fabrikam.com"
Dim exchangeServerLocation As String = "http://fabrikam"
' Create the listener. If you are using Windows credentials,
' pass a null value as the second argument to the ExchangeWebServiceMailBinding.
Dim binding As MailBindingBase
binding = New ExchangeWebServiceMailBinding(New Uri(exchangeServerLocation), New System.Net.NetworkCredential(serverAddress, serverPWD))
Dim parameters As New BindingParameterCollection()
Dim listener As IChannelListener(Of IInputChannel)
listener = binding.BuildChannelListener(Of IInputChannel)(MailUriHelper.CreateUri(channelName, serverAddress))
listener.Open()
Dim inputChannel As IInputChannel = listener.AcceptChannel()
inputChannel.Open()
Dim reply As Message = inputChannel.Receive()
Dim serializer As New CFMessagingSerializer(GetType(String))
Dim str As String = ""
str = reply.GetBody(Of String)(serializer)
' Process the message.
str += ", World!"
' Send the response through an output channel.
Dim m As Message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "urn:test", str, serializer)
Dim channelFactory As IChannelFactory(Of IOutputChannel)
channelFactory = binding.BuildChannelFactory(Of IOutputChannel)(parameters)
channelFactory.Open()
Dim outChannel As IOutputChannel = 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()
End Sub
End Class
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();
}