Android-dev.it Community

 
Annunci

:arrow: Benvenuto!, se non sei ancora un utente registrato: puoi registrati qui, oppure effettua il login
:arrow: Apri un forum sul tuo nuovo smartphone Android e collabora con noi! (dettagli)

www.agendadigitale.org
Image


Sponsor
It is currently Fri May 18, 2012 5:37 pm

All times are UTC + 1 hour


 Topics   Replies   Views   Last post 
No new posts Apri un forum sul tuo nuovo smartphone Android!

[ Go to page: 1, 2, 3 ]

by ReattileGar on Fri May 18, 2012 5:27 pm in Amministrazione

27

12410

Fri May 18, 2012 5:27 pm

ReattileGar

No new posts Новый: базы для хрумера - профессиональный софт для СЕО.

by Renatafe on Fri May 18, 2012 3:14 pm in Amministrazione

0

3

Fri May 18, 2012 3:14 pm

Renatafe

No new posts Pace is undoubtedly the vital affordable Jerseys Wholesale d

by barnettmmolive2012 on Wed May 16, 2012 7:36 am in Amministrazione

1

44

Wed May 16, 2012 7:36 am

barnettmmolive2012

No new posts Problema di compatibilità app

by deran on Tue May 15, 2012 10:44 am in Sviluppo e programmazione in Android

4

186

Tue May 15, 2012 10:44 am

deran

No new posts Applicazione inserimento eventi

by mauro21 on Mon May 14, 2012 9:20 pm in Sviluppo e programmazione in Android

0

23

Mon May 14, 2012 9:20 pm

mauro21




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Call Web Service in Android on GAE
PostPosted: Tue Feb 01, 2011 3:12 pm 
Offline
User avatar

Joined: Tue Feb 01, 2011 2:54 pm
Posts: 2
Cellulare Android: HTC Magic
Operatore: Vodafone
Punti Android: ?
Ciao a tutti,

ho pubblicato online su Google App Engine il seguente Web Service:
***URLs are hidden from guests, please register and login to view the hyperlink***

dove ci sono 3 operazioni:
- createEmployee
- getEmployee
- pingApplication

Dove il primo servizio prende dei parametri dell'Employee e risponde con un booleano, il secondo non lo prendiamo in considerazione e il terzo ha un parametro nullabile e risponde sempre TRUE.

Premetto che ho provato i servizi da SoapUI e da Visual Studio e funzionano!

Volevo provare a fare un applicazione su Android che invoca uno di questi servizi, ad esempio ho scritto questa classe velocemente:
Code:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class Test {
   private static final String SOAP_ACTION = "pingApplicationRequest";
   private static final String METHOD_NAME = "pingApplicationRequest";
   private static final String NAMESPACE = "http://marcoapplicazione.appspot.com/";
   private static final String URL = "http://marcoapplicazione.appspot.com:80/soap/";
   
   public void test() {
       try {
           SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
          
           SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
           envelope.setOutputSoapObject(request);
          
           HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
           androidHttpTransport.debug = true;
           androidHttpTransport.call(SOAP_ACTION, envelope);
          
           Object result = envelope.getResponse();
   
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
   }
}

Di proposito non ho gestito la risposta, perchè quando faccio il call mi cattura la seguente eccezione:
Code:
expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@2:7 in java.io.InputStreamReader@e89b94)

Dalle ore perse a smattetare sul codice e a cercare su google, ho notato che il problema è l'URL, perchè provandone un altro non dà questa eccezione.

Avete qualche idea da suggerirmi????
PS se volete provare x conto vostro non ci sono problema, il servizio è pubblico


Top
 Profile  
 
 Post subject: Re: Call Web Service in Android on GAE
PostPosted: Tue Feb 01, 2011 3:27 pm 
Offline
User avatar

Joined: Thu Dec 27, 2007 7:09 pm
Posts: 659
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 758
Ciao,
devi per forza usare SOAP per il tuo web service oppure sei semplicemente masochista ? :mrgreen:
Che versione della libreria ksoap2 stai utilizzando ? (assicurati di usare l'ultima, che trovi qui: ***URLs are hidden from guests, please register and login to view the hyperlink***.

Se proprio non ne puoi fare a meno, prova a dare un'occhiata qui (ad occhio il tuo codice dovrebbe andare):
***URLs are hidden from guests, please register and login to view the hyperlink***

_________________
***URLs are hidden from guests, please register and login to view the hyperlink***


Top
 Profile  
 
 Post subject: Re: Call Web Service in Android on GAE
PostPosted: Tue Feb 01, 2011 3:52 pm 
Offline
User avatar

Joined: Tue Feb 01, 2011 2:54 pm
Posts: 2
Cellulare Android: HTC Magic
Operatore: Vodafone
Punti Android: ?
Allora stò usando la versione 2.1.2.

Al posto del protocollo SOAP che mi suggerisci?? l'HTTP?


Top
 Profile  
 
 Post subject: Re: Call Web Service in Android on GAE
PostPosted: Tue Feb 01, 2011 4:44 pm 
Offline
User avatar

Joined: Thu Dec 27, 2007 7:09 pm
Posts: 659
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 758
winner03 wrote:
Allora stò usando la versione 2.1.2.

Al posto del protocollo SOAP che mi suggerisci?? l'HTTP?

Personalmente, ho sempre usato l'approccio KISS (keep it simple stupid) per i miei web services: script PHP lato server e chiamate HTTP GET o POST lato client.
Se il web service deve restituire strutture dati complesse, tieni conto che in Android hai il supporto nativo a JSON e XML (più semplice ed efficiente usare il primo, rispetto al secondo, anche se va piu' di moda xml...).

Se cerchi nel forum trovi altri thread in cui si parla di web services, con snippet di codice di esempio.

_________________
***URLs are hidden from guests, please register and login to view the hyperlink***


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

All trademarks and logos used in this site are of properties of their respective owners.