Wednesday, November 22, 2006

PocketPC application with WebService

After spending about 2 days of my life trying to create a PocketPC application that connects with a database through WebServices, I finally made it!

The main problem was that the articles/guides/how-tos that I found on the net, where misleading me instead of helping me. The reason is that some of them didn't mention to which versions they were referring to, and persuaded me to do things that I didn't have to.. So, if you are working with Visual Studio 2005 beta 2, there are some problems that I am not going to discuss. The same goes for VS 2003. What I am using and going to talk about, is Visual studio 2005 and PocketPC 2003 Emulator.

Below I am listing the steps you need to follow and the reason for each one of them. If you don't understand much, just follow the steps and ignore the reason :)

To start with, I need to have a webservice that contains at least a method that returns a Dataset. That dataset is supposed to be filled with a Table from a database.

Then I create a PocketPC project. I add as web reference the webservice to the PocketPC project and then I call the method.. Then I try to build.. Up to here, everything looks normal. But, there are several issues..

1st. The emulator doesn't have internet by default.
The problem is that the emulator considers the device being on hand and not on it's base. What you have to do, is go to Tools->Device Emulator Manager, select "PocketPC 2003 SE Emulator", right click and select Cradle. Now, the Pocket PC device is considered connected with the pc.

But, still that's not enough. You need to download a software the will allow the sharing of your internet connection with the the PocketPC Device (Emulator). This software is freely provided by microsoft, and it is called ActiveSync.

2nd. The Emulator even though is connected to internet, cannot access the webservice.
The problem is that the webservice is running at the localhost(your pc) and your pocketpc is trying to find it at its localhost(the pocket pc).. So, the problem is that both webservice and pocketpc are trying to communicate at localhost, but each one of them mean something different when they say localhost. To fix this, you should define at your pocketpc project, that the web reference that you are using is at your ip and not at localhost. That has to be done in two places. One is the properties of the web reference, and the other one is at reference.cs (at the constructor).

Then everything should work smoothly..
Hopefully :)

2 comments:

vpapanik said...

Τωρα μας έστειλες όλους !

Βασικά τι πακέτο χρησιμοποιείς για να γράψεις εφαρμογή για Pocket PC ; Δεν έχω ιδέα. Και δυστυχώς στο Delphi δεν γίνεται :(

Για δωσε καμιά πληροφορία να ασχοληθώ...

Stavros Amanatidis said...

Όπως έχω ξαναπεί, Visual Studio 2005 Rockz :)

Το να κάνεις μια απλή εφαρμογή PocketPC είναι παιχνιδάκι.. Create new PocketPC application!

Το ίδιο και Websites. Δε μιλάω ως designer, αλλά για το πώς να κάνεις ένα website που να λειτουργεί περίπου σαν windows application. Με κουμπιά με events, classes, κτλ..

Το ίδιο και Web Services.. Create new Web Service.. Αρκεί να έχεις καταλάβει τα βασικά από C#, και προχωράς.