You can create applications that are based on the Windows Communication Foundation (WCF) Exchange Server mail transport to send and receive messages on specified input/output channels, by using a computer that is running Microsoft Exchange Server as the mediator. Applications that are based on the WCF Exchange Server mail transport are supported both on the desktop and on devices.
Building the application for the device (client).
Building the application for the desktop (server).
For a complete listing of the code shown in these procedures, see the Example section at the end of this walkthrough.
Do not use this example in production code.
This example requires the .NET Compact Framework version 3.5.
In this procedure, you make sure that your development environment is set up correctly to run the example.
Install the Windows Mobile version 5.0 or Windows Mobile 6 Software Development Kit (SDK).
The Windows Mobile 6 Professional SDK includes the ActiveSync always-up-to-date (AUTD) feature, which is used by the mail transport on the device to keep the Inbox up-to-date. For more information, see the Windows Mobile Web site.
Make sure that an e-mail server that is running Microsoft Exchange Server 2007 is available on the network.
If you do not have Exchange Server 2007 available, you can use a trial version that runs on Virtual PC. For more information, see the Exchange Server Web site.
Verify that your computer can connect to the new Exchange e-mail server by running Outlook Web Access (OWA) from your computer and connecting to an e-mail account.
Make sure that Exchange Web Services is enabled on the Exchange e-mail server.
One way to verify this is to access the exchange.asmx page on the e-mail server by using one of the following URLs: http://server-address/ews/exchange.asmx or https://server-address/ews/exchange.asmx.
If you are using the emulator, provide your emulator with network capabilities.
The ActiveSync AUTD feature does not run when ActiveSync is providing the network connection. You can use Device Emulator 2.0, which is included with the Windows Mobile 6 Professional SDK or as a separate download, to bind your NE2000 PCMCIA card to a host network adapter by configuring emulator properties.
When you have the emulator up and running, configure ActiveSync to communicate with your Exchange e-mail server. For more information, see "Step 5: Configure and Manage Mobile Device Access on the Exchange Server" in Deploying Windows Mobile 6 Powered Devices with Microsoft Exchange Server 2007 on the Microsoft TechNet Web site.
In this procedure, you build an application for the device that represents the client, and then create and send a message to the server by using the mail transport.
Create a new Smart Device project in Visual Studio.
Add the CFMessagingSerializer class, which is described in How to: Serialize Messages in WCF Applications.
On the desktop, you can use either a custom serializer or attributes to create serialized data. However, we recommend that you use the same serializer for both the device and the desktop.
Create the message and serialize it.
Create variables to represent the channel name, the device e-mail address, and the server e-mail address.
Dim channelName As String = "StoreandFowardMessageHelloWorld"
Dim serverAddress As String = "ServerMailAddress@fabrikam.com"
Dim clientAddress As String = "DeviceMailAddress@fabrikam.com"
' Build the output channel.
// Build the output channel.
Add code to send the message.
Build a listener and add code to listen for the response.
The listener blocks code execution. Therefore, we recommend that you run the listener in a separate thread in your production code. For this example, add the listener code after the sender code.
' Listen for the response.
// Listen for the response.
When a response is received from the server, deserialize the response and present the result to the user.
' When you receive a response, deserialize the message.
// When you receive a response, deserialize the message.
Build the client application and deploy it to the emulator or device that you configured to synchronize with your Exchange e-mail server.
In this procedure, you build an application for a desktop computer, which represents the server in this example. The server processes a message from the client, appends it, and sends it back to the client.
Create a new Windows Console Application.
Create some variables, some of which must correspond to values from the device project.
' Set some global variables.
Dim serverPWD As String = "MyPassword"
Dim exchangeServerLocation As String = "http://fabrikam"
// Set some global variables.
If you are using Windows credentials, pass a null value as the second argument to the ExchangeWebServiceMailBinding object. As on the device, the input channel blocks code execution. Therefore, we recommend that you create a new thread for each listener in your production code.
' pass a null value as the second argument to the ExchangeWebServiceMailBinding.
// pass a null value as the second argument to the ExchangeWebServiceMailBinding.
Add code to process the message.
Add code to send the response through an output channel.
' Send the response through an output channel.
// Send the response through an output channel.
Build the project and start the server application.
Start the client application on the emulator or the device.
The following complete examples demonstrate how to send and receive messages by using the WCF Exchange Server mail transport.
Mail transport security is not enabled in this example. For more information, see WCF Exchange Server Mail Transport.