Introduction
Smart device application with Web Services is very useful for smart device online application. It’s much faster than using Remote Data Access and easier to configure than Replication method.
Main
First we have to add new project in Visual Studio 2005. In this tutorial I’m using Pocket PC 2003 device and C# language. Then add the form with one data grid. Then we add the Web Service like picture below

After the web services project is added, u can see the service.cs class. This is the area where we code
our web service method . The sample “Hello World” method was created for an example.

Now we need to add web reference from the smart device project. I use “WsPPC” as the web service
name. So the full url is http://localhost/WsPPC/Service.asmx, put this url to the url text box in web
reference. Don’t forget “service.asmx” part, or else u cant find the reference. Once its added it will appear like this picture below. I put “WsPPC” as the web reference name, same as the web service project name.

Then hit the Add reference button and your web reference is ready. U can see the web reference on web reference folder in your smart device project. You will need to update your web reference every time you add new method in your web service project. Right click in your web reference and click update web reference. If you found an error while update your web reference, it’s probably there some error on your web services. Now we try to add method Retrieve Employees in web service. I created Company database with Employees table in it.
The Employees table contains:
EmpId varchar (5)
EmpName varchar(50)

Now add this method in service.cs :
[WebMethod] public DataSet GetEmployees()
{
OpenConnection(); string query = "SELECT * FROM EMPLOYEES ";
SqlDataAdapter da = new SqlDataAdapter(query,conn);
DataSet ds = new DataSet();
DataTable dt = new DataTable("Employees");
da.Fill(dt); conn.Close();
ds.Tables.Add(dt); return ds;
}
[WebMethod] public string GetEmployeeName(string empId)
{
OpenConnection(); string query = "SELECT EMPNAME FROM EMPLOYEES WHERE EMPID ='"
+ empId +"' ";string empName;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
empName = cmd.ExecuteScalar().ToString();return empName;
} Don’t forget to add [WebMethod] tag to your web services method, or else it won’t know as the web service method in smart device application. Web service can return any data type such as Data Set, String, Integer, Class etc. But I haven’t figured out how to return Data Table. Now back to the Smart Device form we created before, and put these code on form load event. Don’t forget to import the web reference’s namespace :
using PPCWithWebServices.WsPPC;private void frmEmployee_Load(object sender, EventArgs e)
{
Service webSevice = new Service();
webSevice.Url = "http://localhost/WsPPC/Service.asmx";
dg.DataSource = webSevice.GetEmployees().Tables[0];
} we need to point the web service’s url to the web service location same as the url we use to add the web reference. And if we run it, the result supposed to be like this

Now add another form like this

Put this code on Button employee click
private void btnEmpName_Click(object sender, EventArgs e)
{
Service webService = new Service();
webService.Url = "http://PUTRA/WsPPC/Service.asmx";
txtEmployeeName.Text =webService.GetEmployeeName(txtEmpId.Text.Trim());
} When we click the Get Employee Button the result is :

Web services it very useful if we want to build an online application using smart devices. Its simple, fast and realible.
Download Source Code