I've seen many people, who are facing issues while accessing Web Service on Windows Mobile enabled devices. Although there are lot of posts on blogs and forums, sometimes, it doesn't work. Why? Because there are lot of issues.
Let's see all those issues and solve them. I hope that readers of this blog are aware of creating Web Services in C# / VB.NET using Visual Studio 2005 or 2008.
If not, lets create a simple Hello World web service i.e. a web method, when called will return a Hello World string. By default, when you create any web service in Visual Studio it gives you "Hello World" method as a web method which can be consumed (or used) as web service.
Now, lets see how we can access this web service in Windows Mobile based applications.
1. Create a Windows Mobile based Windows Forms Application
2. Add a Web Reference to your web-service. Now, here is the glitch. While adding a reference it uses your system as a localhost (in some cases port no attached) but when you deploy your application on Windows Mobile, actually your web-service is still running on your development machine and not on your device. Hence, change this localhost with your development machine name OR machine name on which your web service is hosted. Don't use IP address. Why? Because, when you attach your mobile device to the machine, using DHCP it gets automatic IP address. So, don't set any IP address rather use machine name.
3. Now, create a proxy class and use that web service in your application.
4. To test the application, run it in emulator or on device. Now, if you're running your application on real physical device then it should work properly. But, if you're running it on emulator, then make sure that...
a. In ActiveSync -> File -> Connection Settings, you have allowed DMA connections.
b. When Device Emulator is running, in Device Emulator Manager, Cradle your device. That means, it'll connect your device emulator to your machine.
This ways you should be able to consume web service hosted on your machine onto your mobile device (whether real-physical device OR emulator).
I hope, this clarifies and solves most of the issues.
Soon, I will create a Screen Cast and host it on my blog.
Mayur Tendulkar | Microsoft India