Introduction: In this article I'll discuss about how to call Web Service Application from windows mobile desktop application using C#. Background: It's not as you are thinking to create one web service application and call this web service from our windows mobile application. The same thing we are doing here but when you are adding web reference from C# windows form it will work but for windows mobile we have to follow some different technique. We will discuss every basic step of calling web service in windows mobile. For execution of this application you need following software's installed on your system.
Once you have all this software installed on your system we can develop web service application for windows mobile. Let's take a step-by-step look to develop Web services for Windows Mobile. Step 1: As our title we need to first to create our web service application which we will call from our windows mobile application. Open Visual Studio -> New Web Site->Asp.Net Web Service->Name it as WinWebServie. Step 2: Write the methods with attribute [WebMethod] to perform our database or any other task. Let's create one sample webmethod as follows. [WebMethod] public string GetGreetingsWebMessage(string _name) { return "Welcome "+_name+" To Windows Mobile Web Service Application."; } This webmethod taking name as input and return the greetings message to user. Step 3: Build above created web service application and host it in IIS. For hosting web site under IIS check Hosting WebSite Under IIS. Here we have finished our web service application development part. Step 4: Now we have to create our windows mobile application which will call the web service. Open Visual Studio->New Project->Smart Device->Pocket PC ->Name it as WinWebMobile. The result will be as one windows mobile application will be created. Design it with one textbox for accepting argument and one button to invoke the webmethod of web service application. Step 5: It's was only the GUI development part of our application now we can call the web service by adding web reference in our WinWebMobile application for that open solution explorer->right click on references->Add Web Reference will look like bellow and provide the URL of website hoted under IIS. But here you can't specify it as http://localhost/VirtualName/Service.asmx insted of this you have to specify Url as http://<SyatemName>/<virtualNameofWebsite>/Service.asmx then only the reference of webservice will be added to your application and our application can call the webmethods of webservice. If you provide localhost then it will return runtime error as no "No network connection" like this. Add the name to reference as WinWeb. Step 6: Now we have added the reference to webservice application and the webmethods are accessible from our windows mobile application. Write the following code in button_click event to invoke the webmethod. WinWeb.Service obj = new WinWebMobile.WinWeb.Service(); if (textBox1.Text!="") { MessageBox.Show(obj.GetGreetingsWebMessage(textBox1.Text).ToString()); } else { MessageBox.Show("Enter Name"); } Step 7: Now we have done all the things and we are near to execute our application but it not as simple like press F5 and run our application for this we need to follow this step as bellow.
Conclusion: In this way we can call the web service from our windows mobile application.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: