Up to now I haven't explained what my mobile test application does. The main thing I wanted to test was calling a WCF service. If you use .NET CF 3.5 WCF will be available in your application to make the call but you can also call the service as "web service" (asmx)
(1) Calling the service as ASMX
In you Smart Device Application project just do "Add Web Reference", enter the url of the service (no "mex" part but with final /, like this: http://server:port/Design_Time_Addresses/WcfService/Service1/) and your are done.
This is the code I use in the device application to call the web service:
Service1WebReference.Service1 svc = new Service1WebReference.Service1();
IWebProxy proxyObject = new WebProxy(this.proxyAddress, true);
proxyObject.Credentials = System.Net.CredentialCache.DefaultCredentials;
svc.Proxy = proxyObject;
string response = svc.GetData(i, true);
I had to specify the proxy address otherwise it would not work. The first time I call the service I get prompted for the credentials.
(2) Calling the service as WCF
The first thing you will notice is that in the Smart Device Application project, there is not option to "Add Service Reference". GRRRR ... You need to install the Power Toys for the Microsoft .NET Compact Framework. Then, you can use the NETCFSvcutil utility to generate the proxy code. Like this:
"C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin\NetCFSvcUtil.exe" http://server:port/Design_Time_Addresses/WcfService/Service1/
The utility generates two files (Service1.cs and CFClientBase.cs) that you have to add to your project.
This is the code I use in the device application to call the WCF service:
Service1Client client = new Service1Client();
string response = client.GetData(i);
Remarks
Notice that you have to use your machine IP as server name and not "localhost". Otherwise, your smart device will not be able to locate the service.
Several other blogs explain how to connect the emulator and your desktop machine: for example, here. (This is for Pocket PC or Smartphone emulators that are proviced by the SDK; if you can to use the Windows CE 5.0 emulator, read this and see my previous blog post).