7

I want to generate a android(java) based STUB for accessing all the web services. I have tried generating the stub using following tools:

1) Sun Java (TM) Wireless Toolkit 2.5.2_01 for CLDC,

2) ksoap2-generating-stub-0.1-SNAPSHOT-J2me-Android.

But i was unable to generate a proper stub that can be used. Please suggest any library or tool that you have used for the purpose.

thanks!!

Anyone here!!

Update:

Problem with sun java lib: There are some java libs that are not supported by Android. For eg: "javax.microedition.xml.rpc.Operation" etc.

Problem with ksoap2: getting a null pointer exception with following log in command prompt:

command that i run using windows command prompt:

java -cp ksoap2-generating-stub-0.1-SNAPSHOT-jar-with-
dependencies.jar;"%JAVA_HOME%\lib\tools.jar"
ksoap2.generator.Wsdl2Android -w "http://localhost:8080/Ws2Ksoap/
services/HelloWorld?wsdl" -g .\generated

As soon as i am running this code,i am getting following exception:

Exception in thread "main" java.lang.NullPointerException
        at ksoap2.generator.WsCompiler.compile(WsCompiler.java:86)
        at ksoap2.generator.WsCompiler.run(WsCompiler.java:78)
        at ksoap2.generator.Wsdl2J2me.run(Wsdl2J2me.java:116)
        at ksoap2.generator.Wsdl2Android.main(Wsdl2Android.java:41) 

Another Update: The created web services must not use any instance of java.rmi.* package.

mudit
  • 25,306
  • 32
  • 90
  • 132
  • Why not just program it? – Miguel Morales May 09 '11 at 19:53
  • There are a lots of api calls plus lots of custom collection types. It will take much more time in coding all those api myself. – mudit May 10 '11 at 05:28
  • so you have a wsdl file or something and you want to generate a stub so your android program can invoke the web service methods? – kharles May 13 '11 at 05:33
  • What problems are you facing with the 2 libs you have mentioned above ? – Soumya Simanta May 16 '11 at 20:31
  • @soumya: check the update in my question. – mudit May 17 '11 at 06:08
  • i toyed around with some soap clients for previously, and never could really get wsif and simplesoap to work. in the end i settled on the bulky axis2. it worked, but i dunno if that'll work for android and it's probably too bulky. if you go down the axis2 path i can try to help with any problems you encounter. – kharles May 20 '11 at 04:24
  • 1
    @kharles, thanks for your response, i tried using axis2 but it uses some java classes which are not supported by android. So cant go that way.. – mudit May 20 '11 at 07:12
  • Same problem here. I am wondering if you have solved the problem. – Hong May 16 '13 at 11:46
  • Cut your pain with this service http://www.davidgouveia.net/android-ksoap2-stub-generator/ It generates stubs based on the same lib. – Nikola Despotoski Aug 10 '13 at 01:57

2 Answers2

2

This exception occurred because you run java from JRE, but it searches for a compiler and can't find it. Use java.exe from JDK, like this:

"c:\Program Files\Java\jdk1.6.0_20\bin\java.exe" -cp ksoap2-generating-stub-0.1-SNAPSHOT-jar-with-dependencies.jar;"%JAVA_HOME%\lib\tools.jar" ksoap2.generator.Wsdl2Android -w "http://address/Service.svc?wsdl" -g .\generated
Mindphaser
  • 2,187
  • 1
  • 16
  • 5
2

have you included the ksoap2 jar file to your project ...? I had done and example of webservice using ksoap2 and got it successfully. I had used and online web service of www.w3schools.com, the details of the web service are as follows....

soap_action = "http://tempuri.org/CelsiusToFahrenheit"; method_name = "CelsiusToFahrenheit"; namespace = "http://tempuri.org/"; url = "http://www.w3schools.com/webservices/tempconvert.asmx";

hope this will help you.Good Luck

  • Hi Jannat, Can you give some example links or tutorial OR may be a code sample? That will be really helpful. – mudit May 18 '11 at 06:08
  • 3
    thanks for the video. But this is not something i am looking for. I am looking for this: I have a WSDL file which contains some methods(which return some complex object). Now i want to generate java code using some tools which i can use for accessing those methods. – mudit May 18 '11 at 09:18
  • @mudit..please post a solution if u got one. it will really nice if u will help me as i got the same problem..' – Amritpal Singh Apr 01 '13 at 13:50
  • @AmritpalSingh: No i didnt get a solution for this. I wrote this whole stub myself.. whole service connection logic, response parsing etc.. – mudit May 19 '13 at 11:54