Apr 29, 2008

Web Service On Windows Mobile

Yes.

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.

Namaste.....

Mayur Tendulkar | Microsoft India

10 comments:

Kumar Kush said...

Hi Mayur
U have done a good job. Your illustration really demonstrated the concept very well.
Thanks and All The Best

Kumar Kush said...

Hi Mayur
U have done a good job. Your illustration really demonstrated the concept very well.
Thanks and All The Best

Kumar Kush said...

Hi Mayur. When I invoke the service, instead of getting simply Hello World, I get the following XML code. How do remove that?
"xml version="1.0" encoding="utf-8" ?
string xmlns = "http://impetus.co.in/""
Hello World
/string

Thanks in advance

Dhawal Yogesh Bhanushali said...

Honestly a very good post. I appreciate the timing. Currently i am working on a project where i needed to connect to the emulator. I was facing a lot of troubles and u soved them all !!! way to go buddy.

Mayur Tendulkar said...

Kumar Kush :>
1. Thanks for appreaciating.
2. You're invoking that web-service. I'll say you need to use it, in some applications OR CONSUME it.
Will create one screen-cast on it.

Dhaval :>
My pleasure sir. Just coincidence and I hit the right topic. Let me know if I can put more over here.

Dhawal Yogesh Bhanushali said...

Yes I have a featre request in your demo. please make ur demo webservice to transfer images or audio too. and consume them with or witout using datagrid.

i am currently using an arraylist to transfer but unable to marshal the Arraylist at the consumer[client]. EEELLLPPP!!!

Hell Boy said...

Hi,
I am trying to run a webservice on windows mobile 5.0 device via visual studio. i am not able to change the localhost name to my development pc name. can u please tell me how to do this.
I am new to webservice and asp, so please help.

aryan said...

Hi Mayur,
Your blog provided me what i was exactly looking for, but i have a doubt. I an new to C# and .Net, can you please tell me how to do the step 3 that is creating a proxy class, is it created automatically? If yes then how to use it in the project.
Thanks

Aryan

Smita said...

Hi Mayur,

Your illustration was really helpful. I am using windows mobile 5.0 on vista (VS 2008). I have set the connection in windows mobile device center to DMA. Still I get the error "connection is not set".

Can u please help me with this?

SmitaVishal said...

thanks. it works well with ipaddress on vista