다음을 통해 공유


Visual Studio 2005 Device Emulator and Webservice

I have seen few people finding difficulties with the testing their web service with the device emulator. In the following we will

1. Create a simple "Hello Mobile" web service using Visual Studio 2005.

2. Create a smart-device application that will access this web service from Device Emulator.

"Hello Mobile" web service using Visual Studio 2005

Visual Studio 2005 has made life luxurious for developers. It is really very simple to create an ASP.NET web service using Visual Studio 2005.

1. Go to menu File->New->Web Site in Visual Studio 2005. It will open up a dialog as shown following. Select the ASP .NET Web Service and in the "Language" drop-down select your preference language. I will select Visual C# as my preference language.

2. Now click OK. This will create the web service and open up a App_Code\Service.cs file. I will modify the HelloWorld method in this file to return string “Hello Mobile”. Now in the solution explorer, right click on the website solution and click “Build Web Site”

3. From the solution explorer, right click on the web-site project and select “View in Browser”. This will start the ASP .NET development server and opens in Internet explorer directory listing. For me the Root URL to the service is https://localhost:1607/WebSite12. This will differ for you.

Now we are ready with a “Hello Mobile” web service. We will create a smart-device application from which we will access this web service.

Smart-device application to access the “Hello Mobile” web service

1. In the Solution Explorer, right click on the solution and select Add->New Project. Now create a Visual C# Smart Device application.

2. Now we will add a button to the form-designer using tool-box as shown following.

3. Double click on the button in the form-designer window; this will take you to event handling code for the button click.

4. Now right click on the Device Application in solution explorer and click “Add Web Reference”. In the “Add Web Reference” dialog, select “Web Services in this solution”; it will show the web service we created above. Select it and click on the “Add Reference” button.

5. Now add following code to access the web service, so that I get a MessageBox with the string from the web service. Note the gocha in the Url, it refers to your machine name and not localhost as was used when accessing web service from desktop.

           localhost.Service service = new DeviceApplication1.localhost.Service();
            service.Url = "https://<machine name>:1607/WebSite12/Service.asmx";
            string str = service.HelloWorld();
MessageBox.Show(str)

6. Using the Tool->Connect to Device, start PPC 2003 SE emulator. Also Cradle it using Device Emulator Manager. Set the Device Project as the start-up project. Use F5 to deploy and run the application on PPC 03 SE.

7. Now in the application in PPC 03 emulator, click on the button and it pops up a message box with the string “Hello Mobile” returned from web service.

Comments

  • Anonymous
    November 23, 2006
    PingBack from http://suniljagadish.wordpress.com/2006/11/24/windows-mobile-50-emulator-and-webservice-woes/

  • Anonymous
    February 26, 2009
    To do this, host PC (running localhost) needs Internet connection or can it be a disconnected machine?

  • Anonymous
    July 03, 2010
    now for example if my pc name is  "homepc" the url should be : service.Url = "http://homepc:1607/WebSite12/Service.asmx"; will this work? note: i haven't connected to any external network.

  • Anonymous
    November 07, 2013
    Well, did it work when PC is not connected to local LAN or Internet?