Arslan Anwar
Arslan Anwar

Reputation: 18746

HTTP GET method to SOAP in android, Please correct me

I am using a webservice. I have used HTTP GET for all the functionality. But this functionality need to send a long XML which is getting problem fo query length to much long. I know that service also support SOAP 1.1 , 1.2 But I have never ever used SOAP I am confused how to do this. I google and found some examples. I am trying to use Example for me. Please I am trying to convert by this Page

http://200.26.174.211/WsServices/WsServices.asmx?op=PagoFactura

This is the HTTP GET URL I am using and want to replace it with SOAP

HTTP GET

GET /WsServices/WsServices.asmx/PagoFactura?AppUsuario=string&AppPassword=string&Usuario=string&Password=string&monto=string&cantidadFacturas=string&IdEmpresaServicio=string&IdUsuarioEmpresaServicio=string&IdCuenta=string&cvv=String&xmlFacturas=string HTTP/1.1
Host: 200.26.174.211
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

To this

POST /WsServices/WsServices.asmx HTTP/1.1
Host: 200.26.174.211
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/PagoFactura"

<?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
<PagoFactura xmlns="http://tempuri.org/">
  <AppUsuario>string</AppUsuario>
  <AppPassword>string</AppPassword>
  <Usuario>string</Usuario>
  <Password>string</Password>
  <monto>decimal</monto>
  <cantidadFacturas>int</cantidadFacturas>
  <IdEmpresaServicio>int</IdEmpresaServicio>
  <IdUsuarioEmpresaServicio>int</IdUsuarioEmpresaServicio>
  <IdCuenta>int</IdCuenta>
  <cvv>string</cvv>
  <xmlFacturas>string</xmlFacturas>
</PagoFactura>
  </soap:Body>
 </soap:Envelope>

This is the Android code found in example. I am confused how do I put the above into android code. Please help me about XMLNS and Method name

private static final String SOAP_ACTION = "myMethod";
private static final String METHOD_NAME = "myMethod";
private static final String NAMESPACE = "http://mynamespace.com/";
private static final String URL = "http://myserver.com/bean";

void test() {
try {
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("prop1", "myprop");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.call(SOAP_ACTION, envelope);

    Object result = envelope.getResponse();

    //handle result here

    myExampleHandler.getResults();
} catch (Exception e) {
    e.printStackTrace();
}
}

Upvotes: 0

Views: 1047

Answers (1)

Lalit Poptani
Lalit Poptani

Reputation: 67286

Here is a nice video tutorial for dealing with webservice using k-soap:

Example

Upvotes: 2

Related Questions