1

I am facing a problem in connecting my Android code to a .NET web service i.e I am not able to call the web service from within the emulator. My web service is a simple HelloWorld web service that comes by default when u select web service project is VS2008. It is named Service1.asmx

Android code link :[http://pastebin.com/AGEZSKue]

can anyone give me a solution to my problem ?

Parth Doshi
  • 4,200
  • 15
  • 79
  • 129

4 Answers4

3

This is what you should add to your Manifest.xml file

<user-permission android:name="android.permission.INTERNET"></user-permission>
<user-permission android:name="android.permission.ACCESS_NETWORK_STATE"></user-permission>
hackp0int
  • 4,052
  • 8
  • 59
  • 95
  • ok and what abt the url , namespace and other stuffs of my code ? Do u think they are fine or should I change those? – Parth Doshi Jul 24 '11 at 09:17
  • I added the permissions ...still it's giving same problem ..emulator screen shows "Hello world ,ksoapexample Permission denied" – Parth Doshi Jul 24 '11 at 09:20
  • Sorry i didnt check the code carefully. You are already using KSOAP. I think suggestion from @IamStalker should work +1 to IAM – Pinakin Shah Jul 24 '11 at 09:31
  • @IamStalker : can u help me connecting my emulator to the .net web service . i am new to all this . It is giving me an error when I typed the url in the browser of my emulator. It gives "HTTP 404 error source cannot be found" can u help me solve this ? – Parth Doshi Jul 24 '11 at 10:10
  • After i have added the xml above i've been able to use browser as usual test with google.com and see if it's ok? – hackp0int Jul 24 '11 at 11:02
2

What error are you seeing reported?

This might just be due to network limitations - either with the cassini development web server or with iis express.

Check out this question and answer - Android Emulator loopback to IIS Express does not work, but does work with Cassini

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165
  • On the emulator screen when the code runs I get this output "Hello World, ksoapsample Permission Denied " ...that's it I can't see the correct output which is "helloworld" coz my webservice returns just that – Parth Doshi Jul 24 '11 at 09:15
  • This is either due to permissions in the app (see @IamStalker's answer) or its due to permissions on the web server - in which case see the question/answer I linked to. – Stuart Jul 24 '11 at 09:19
  • ok and what abt the url , namespace and other stuffs in my code ? Are they proper or should I change those too ? Also in the link u have given it's written : netsh http add urlacl url=http://[machiniename]:[port]/ user=everyone netsh http delete urlacl url=http://[machinename]:[port]/ so where to rite this commands ? – Parth Doshi Jul 24 '11 at 09:23
  • comparing your code with a working example in http://stackoverflow.com/questions/1048310/how-to-call-a-net-web-service-from-android it looks like your's should work - I can't advise on whether you have correct port number - that depends on how your webserver (or development webserver) is setup. – Stuart Jul 24 '11 at 09:26
  • I have IIS installed which runs on localhost ..i just simply type http://localhost in my browser and the IIS page appears. My question is what is then my port number , how to I find it ? Also if I do find it , where should I write those commands "netsh..." command prompt? – Parth Doshi Jul 24 '11 at 09:30
  • If you are running on http://localhost, then your port number is 80. If you are running full IIS, then you shouldn't need the other commands. Is your web service within IIS listening on "10.0.2.2" (from your code)? If not, then change that IP address so that it is a correct address. (Can you browse to that web service from the chrome browser on android?) – Stuart Jul 24 '11 at 09:33
  • Also If u compare my code to the one for the question u have provided, in that the url is "http://192.168.1.19/TestWeb/WebService.asmx" and if that code works then I need to change my url to "http://[myip]/Service.asmx" ..I don't understand what is the TestWeb that is mentioned in the url – Parth Doshi Jul 24 '11 at 09:35
  • `TestWeb` is just part of the path to the service. – Stuart Jul 24 '11 at 09:36
  • ok TestWeb part I clear..I don't have that path so my url won't contain TestWeb that's for sure. btw i launched the emulator, opened the browser and typed http://[my machine ip]/Service1.asmx and i got an error on my screen "HTTP error 404 not found the resource u are been looking for has been removed or is temporarily unavailable " now wat should i do ? – Parth Doshi Jul 24 '11 at 09:42
  • @Stuart let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1777/discussion-between-parth-90-and-stuart) – Parth Doshi Jul 24 '11 at 09:45
  • well, you need to get that working before you do anything else! If you can't see the service over http in a browser, then your app isn't going to see it either... my advice, take a deep breath, write down where the service is installed, get it working from a browser on your pc, get it working from a browser on a separate pc (if you have one), get it working from a browser on the emulator, then get it working from the app. One step at a time and you will get there. Good luck! – Stuart Jul 24 '11 at 09:46
  • nope - I'm heading out for a 50 mile cycle ride now - good luck! – Stuart Jul 24 '11 at 09:52
1

Try to insert the Permissions NOT in the XML File, try to insert it via the Permission Tab in the ecplise view. Helped in my case.

chris
  • 11
  • 1
0

You need a REST Service (check WCF Rest) to connect with Android. There are third party libs available for consuming SOAP Web Service

Pinakin Shah
  • 877
  • 2
  • 12
  • 25
  • If u use REST ..den should I create a WCF project in Visual studio 2008? What will be my code then both in VS2008 and Android ? Which third party libs can I use to for SOAP get my problem solved? – Parth Doshi Jul 24 '11 at 09:13