Geeks With Blogs
Clara's Notes on Technology Notes to me and the world

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



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).


Posted on Thursday, May 7, 2009 12:38 PM | Back to top

Comments on this post: Developing for Mobile (3): Calling a WCF/ASMX Service

# re: Developing for Mobile (3): Calling a WCF/ASMX Service
Requesting Gravatar...
Hi Clara
Please keep posting notes. I am a few steps behind you pretty much with the same agenda. I need to learn to communicate with at Memor and your three notes has proved very helpfull. Hope I can return the favor to you soon. :-)

Left by Jesper Dissing Henckel on May 15, 2009 10:57 AM

# re: Developing for Mobile (3): Calling a WCF/ASMX Service
Requesting Gravatar...
Please do keep posting. Your blog is well-written and has been quite useful to me so far. For whatever reasons there seems to be a real dearth of material out there regarding the use of WCF-based communications when the client is running Windows CE. That is our situation here (we want to build a robot using a distributed architecture, with a host machine running XP and a number of component embedded systems each running CE) and I was really starting to wonder about how we would be able to make the communications happen. I've very glad that you're blazing this bold path forward -- please keep up the good work, and hopefully I'll be able to reciprocate with some useful information for you one day.<p>
Best wishes,<br/>
Left by Ben on May 28, 2009 3:28 PM

# re: Developing for Mobile (3): Calling a WCF/ASMX Service
Requesting Gravatar...
I would like to thank you for these two really nice comments. There is indeed a lack of information about developing for mobile applications. That is what we have blogs for.

Unfortunately, I don't think I will be doing this mobile project because it has been delayed and I am going on maternity leave really soon. (Unless it is delayed for so long that it is still here when I come back in 6 months).
Left by Claraoscura on May 28, 2009 3:36 PM

# re: Developing for Mobile (3): Calling a WCF/ASMX Service
Requesting Gravatar...
am sry about my question but i don't know how to use this NetCFSvcUtil.exe i have mobile app project and i have wcf secrvice project how can i call this service in my mobile app project i installed power toys and when my question is how to run the NetCFSvcUtil.exe and in any path i put this and all things am sry :(
Left by ashraf elhakim on Apr 12, 2010 12:35 AM

Your comment:
 (will show your gravatar)

Copyright © Clara Oscura | Powered by: