read


<ul><li>Include Ksoap for android in the project or Download here</li></ul><ul><li>Code to call the webservice:</li></ul><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><div class="p3"> </div><pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"> public static String loadMethod() throws IOException, XmlPullParserException {
// WebService properties
final String namespace = "http://namespace.com";
final String methodName = "getSomething";
final String soapAction = "http://namespace.com/getSomething";
final String url = "http://namespace.com/getSomething";
return callWebService(namespace, methodName, soapAction, url, null);
</pre><pre style="background: none repeat scroll 0% 0% rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"> /**
*
* Call a web service and return the response
*
* @param namespace
* @param methodName
* @param soapAction
* @param url
* @param arrayProperties
* attributes of the web service (method parameters)
* @return xml String with the response
* @throws IOException
* @throws XmlPullParserException
*/
public static String callWebService(final String namespace, final String methodName, final String soapAction,
final String url, final PropertyInfo[] arrayProperties) throws IOException, XmlPullParserException {
SoapPrimitive resultsRequestSOAP = null;
// Se crea un objeto SoapObject para poder realizar la peticion// para consumir el ws SOAP. El constructor recibe// el namespace. Por lo regular el namespace es el dominio// donde se encuentra el web service
final SoapObject request = new SoapObject(namespace, methodName);
if (arrayProperties != null) {for (final PropertyInfo propertyInfo : arrayProperties) {request.addProperty(propertyInfo);}
}
// Se crea un objeto SoapSerializationEnvelope para serealizar la// peticion SOAP y permitir viajar el mensaje por la nube// el constructor recibe la version de SOAP
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true; // se asigna true para el caso de que el WS sea de doNet

// Se envuelve la peticion soap
envelope.setOutputSoapObject(request);
// Objeto que representa el modelo de transporte// Recibe la URL del wsfinal HttpTransportSE transporte = new HttpTransportSE(url);
try {
transporte.debug = true;// Hace la llamada al wstransporte.call(soapAction, envelope);// Se crea un objeto SoapPrimitive y se obtiene la respuesta// de la peticionresultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
}
catch (final IOException e) {
throw e;}
catch (final XmlPullParserException e) {
throw e;}
// Almacenamos el resultado en un String ya que lo que represa
// el ws es una cadena json, representando una lista AndroidOS
// de objetos del tipo
return resultsRequestSOAP.toString();
}

</pre>

Blog Logo

Daniel Gomez Rico


Published

Image

MakinGIANTS

The findings and tips records of an Android-iOS-TheWholeShabang group

Back to Overview