javaandroidweb-servicessoapksoap

KSOAP generated SOAP request don't cause any error but not working


Here is my issue :

Generated by KSOAP2 3.6.1 android : Don't cause any XML/SOAP error but webservice record 0 as IdMaquina in data base. Value inserted is wrong(it is not the value I've sent). Webservice response is OK.


<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    <v:Header />
    <v:Body>
        <IngresarMaquinaLog xmlns="http://tempuri.org/">
            <maquinaLog>
                 <IdMaquina>123</IdMaquina>
            </maquinaLog>
        </IngresarMaquinaLog>
    </v:Body>
</v:Envelope>

Generated by Boomrang chrome plugin : Working fine. Value inserted in database is right(It equals the value I've sent). Webservice response is OK.


<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:obe="http://schemas.datacontract.org/2004/07/myService.Entidades">
    <x:Header/>
    <x:Body>
        <tem:IngresarMaquinaLog>
            <tem:maquinaLog>
                <obe:IdMaquina>4567</obe:IdMaquina>
            </tem:maquinaLog>
        </tem:IngresarMaquinaLog>
    </x:Body>
</x:Envelope>

Using as maquinaLog definition:

{ public class maquinaLog implements KvmSerializable { public int IdMaquina;

    public maquinaLog(){}


    public maquinaLog(int idMaquinaField) {

        IdMaquina = idMaquinaField;

    }


    public Object getProperty(int arg0) {

        switch(arg0)
        {
            case 0:
                return IdMaquina;
        }

        return null;
    }

    public int getPropertyCount() {
        return 1;
    }

    public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
        switch(index)
        {
            case 0:
                info.type = PropertyInfo.INTEGER_CLASS;
                info.name = "IdMaquina";
                break;
            default:break;
        }
    }

    public void setProperty(int index, Object value) {
        switch(index)
        {
            case 0:
                IdMaquina = Integer.parseInt(value.toString());
                break;
            default:
                break;
        }
    }
}
}
</code>

Using to build SOAP request: { public void WebServiceCallExample(Integer idmaquina) { String NAMESPACE = "http://tempuri.org/"; String METHOD_NAME = "IngresarMaquinaLog"; String SOAP_ACTION = NAMESPACE + "IMyService/IngresarMaquinaLog"; String URL = "http://MyUrl/MyService/MyService.svc";

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.implicitTypes = true;
    envelope.setAddAdornments(false);

    maquinaLog ML = new maquinaLog();
    ML.IdMaquina = idmaquina;

    PropertyInfo pi = new PropertyInfo();
    pi.setName("maquinaLog");
    pi.setNamespace(NAMESPACE);
    pi.setValue(ML);
    pi.setType(ML.getClass());
    request.addProperty(pi);

    envelope.setOutputSoapObject(request);

    envelope.addMapping(NAMESPACE, "maquinaLog",new maquinaLog().getClass());

    androidHttpTransport.debug = true;

    try
    {
        //Log.i("app", androidHttpTransport.requestDump);

        androidHttpTransport.call(SOAP_ACTION, envelope);
        Log.i("appRQS", androidHttpTransport.requestDump);
        Log.i("appRSP", androidHttpTransport.responseDump);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

}
}


Solution

  • Finally I succeed to match the Boomrang chrome plugin query.

    In complex object definition I've added :

    public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
        switch(index)
        {
            case 0:
                info.type = PropertyInfo.INTEGER_CLASS;
                info.name = "obe:IdMaquina";
                break;
            default:break;
        }
    }
    

    and I've added an attribute to the enveloppe :

    PropertyInfo pi = new PropertyInfo();
    pi.setName("maquinaLog");
    pi.setNamespace(NAMESPACE);
    pi.setValue(ML);
    pi.setType(ML.getClass());
    request.addProperty(pi);
    request.addAttribute("xmlns:obe","http://schemas.datacontract.org/2004/07/OberthurService.Entidades");