Web Services - An XML-RPC Client for Android

Tutorials with advanced 'difficulty' and more Lines of Code.

Server.py ?

Postby discover_dileep » Wed Jan 07, 2009 8:58 am

Hi mkorenba
Thanks for ur reply.When I am executing that code then on emulator one message is appearing : "before calling any application make sure server.py is running".Whats the meaning of this?
please reply.
discover_dileep
Developer
Developer
 
Posts: 33
Joined: Tue Oct 21, 2008 2:19 pm

Top

Postby mkorenba » Wed Jan 07, 2009 8:52 pm

Sorry, I have not seen that message before. I was able to import the src into my project and utilize the classes without issue.
mkorenba
Freshman
Freshman
 
Posts: 4
Joined: Wed Nov 26, 2008 5:02 pm

Re: Server.py ?

Postby pskink » Wed Jan 07, 2009 9:33 pm

discover_dileep wrote:Hi mkorenba
Thanks for ur reply.When I am executing that code then on emulator one message is appearing : "before calling any application make sure server.py is running".Whats the meaning of this?
please reply.


hi, i'm author XMLRPC you downloaded.

when you look into sources you'll see server.py python script in the root of source tree. just run it: either double click when on win32 or 'python server.py' otherwise

btw: the latest version is hosted via svn on google: http://code.google.com/p/android-xmlrpc

pskink
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby Artur79 » Thu Jan 15, 2009 5:36 pm

works great! :) cheers pskink
here's a quick tutorial how to install Python on Windows and Apache
http://news.softpedia.com/news/Your-Fir ... 1974.shtml
Artur79
Developer
Developer
 
Posts: 26
Joined: Fri Sep 26, 2008 12:53 pm

Postby Klaser » Sat Feb 07, 2009 8:44 pm

Hi pskink!

I tried your XMLRPC and it works really well! Thx alot :)
I have a small problem though:
When I call a service that returns a XML-document as a string param it seems that the XMLRPCSerializer.deserialize handles the " chars wrong?

Heres my test code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Map<String, Object> map = new HashMap<String, Object>();
  3.  
  4. map.put("api_key", api_key);
  5.  
  6. map.put("artist", "Cher");
  7.  
  8. Object[] params = {map};
  9.  
  10. result = (String) client.call("artist.getinfo", params);
  11.  
  12.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


After this the first part of result contains the following char array:
<,?,x,m,l, ,v,e,r,s,i,o,n,=,\\,",1,.,0,\\,", ,e,n,c,o,d,i,n,g,=,\\,",u,t,f,-,8,\\,",?,>
which ends up as the string:
<?xml version=\"1.0\" encoding=\"utf-8\"?>

I dont understand where the extra \ comes from?
Am I doing something wrong? Or does the library not support XML in the string param tag of the XMLRPC response?

Cheers!
Klaser
Freshman
Freshman
 
Posts: 5
Joined: Wed Jan 28, 2009 2:50 pm

Postby pskink » Tue Feb 10, 2009 11:58 am

Klaser wrote:
I dont understand where the extra \ comes from?
Am I doing something wrong? Or does the library not support XML in the string param tag of the XMLRPC response?

Cheers!


Klaser,

try to change provided server.py to return some xml file. i did it and it seems that you can return any valid string. i think that your server adds additional '\' chcracters
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Postby Klaser » Tue Feb 10, 2009 12:50 pm

pskink,

Thank you for your reply!
I tried changing the server.py to return a string containing a XML-document and it works great.
The service I use that returns the malformed XML is Lastfm. Here is my complete code with a working test api-key:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. XMLRPCClient client = new XMLRPCClient("http://ws.audioscrobbler.com/2.0/");
  3.  
  4.  
  5.  
  6. try{
  7.  
  8.     Map<String, Object> map = new HashMap<String, Object>();
  9.  
  10.     map.put("api_key", "b25b959554ed76058ac220b7b2e0a026");
  11.  
  12.     map.put("location", "madrid");
  13.  
  14.     Object[] params = {map};
  15.  
  16.     String result = client.call("geo.getEvents", params).toString();
  17.  
  18. }
  19.  
  20. } catch (XMLRPCException e) {
  21.  
  22.     e.printStackTrace();
  23.  
  24. }
  25.  
  26.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


The only possible solution I can see is that there is something wrong with the response from Lastfm, but that sounds a bit unlikely?

Any input is much appreciated :)

Cheers!
Klaser
Freshman
Freshman
 
Posts: 5
Joined: Wed Jan 28, 2009 2:50 pm

Postby pskink » Tue Feb 10, 2009 1:36 pm

Klaser wrote:The only possible solution I can see is that there is something wrong with the response from Lastfm, but that sounds a bit unlikely?

Any input is much appreciated :)

Cheers!


Klaser,

hmm, i think you should check raw lastfm response: try ethereal or something similar (i work on linux and use ngrep in that situations). please tell me what raw lastfm response was
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby pskink » Tue Feb 10, 2009 1:47 pm

Klaser,

also you can use latest version from svn at http://code.google.com/p/android-xmlrpc/

it has some simplified api so if you have less than 8 parameters to pass to the server you dont have to use Object [] array (just use one of 8 convenience method), it supports also passing any Object implementing XMLRPCSerializable interface.
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby Klaser » Tue Feb 10, 2009 2:56 pm

pskink,

Thank you for your quick response.
I tried ethereal, but it wouldnt install. Instead I used Wireshark and captured the following response from lastfm:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <methodResponse>
  2.  
  3. <params>
  4.  
  5. <param>
  6.  
  7. <value>
  8.  
  9. <string>
  10.  
  11. &lt;?xml version=\&quot;1.0\&quot;
  12.  
  13.  
  14.  
  15. etc..
  16.  
  17.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


To my knowledge the \ should'nt be there in the \&quot, so it looks like that's where the problem is!
Again thank you so much for your help!

Cheers! :D
Klaser
Freshman
Freshman
 
Posts: 5
Joined: Wed Jan 28, 2009 2:50 pm

Postby pskink » Tue Feb 10, 2009 3:38 pm

Klaser wrote:
To my knowledge the \ should'nt be there in the \&quot, so it looks like that's where the problem is!


you are right: ["] character is encoded as &quot; so you have to replace every " with "

i think String has replace() method.
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Need Help in Android

Postby karthick » Thu Aug 06, 2009 10:43 am

i want to call web service in axis

i have tried to call the axis web service in android using ksoap2 libray.

i'm getting error "Your application closed unexpectedly " in android.

i have tried lot of sample .

still i am in that problem.

can any one give me the solutions in step by step ?

i have written the web service in axis . and i can invoke it using ksoap2 in normal java program but not in android...
hi i am here to share my knowledge
karthick
Freshman
Freshman
 
Posts: 3
Joined: Thu Aug 06, 2009 10:34 am

Postby konic » Fri Sep 25, 2009 7:17 pm

Hi,

I read this tutorial and in the first words it says that KSOAP has some "resource" issues on Android.
The link provided doesn't explain (much) of these issues.
Next, the tutorial itself looks OK but because it contains so many steps including "fixing" source it looks suspicions.
At the end I learned that to be able to run this client on simulator I need to install Python(!?)
Did I miss something?
As for me I had no problem to use KSOAP2 on Android and so far did not observe any critical issues.
(Was it because I successfully used almost the same source on Blackberry?)
FYI there is ANDROID dedicated build of KSOAP2 (http://code.google.com/p/ksoap2-android/)
which I used (as jar file, no source fixing) and it works.
So, please somebody explain me why usage of xmlrpc would be preferable?
P.S. I am not saying that KSOAP2 is better, just don't see why would I consider using xmlrpc?
konic
Developer
Developer
 
Posts: 32
Joined: Mon Aug 24, 2009 3:16 pm

Postby padde » Fri Sep 25, 2009 7:57 pm

Well.. the thread started early 2008.. things changed since then.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Re: Web Services - An XML-RPC Client for Android

Postby willdevv » Wed Feb 16, 2011 8:11 am

Yes I can import the src into my project so it isn’t normal to not to utilize it to the project. I tried once the XMLRPC and it worked that time too. I just want to test it on the latest release this time.
willdevv
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 16, 2011 7:59 am

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests