Search code examples
androidparametersksoap2

Problem to pass parameter to a webservice using ksoap2 in Android


I have a strange problem with DotNet Service and Android (Ksoap2). I'm using this code :

        // Création de la requête SOAP
    SoapObject request = new SoapObject ("http://webservicesobject.url.fr/", "GetPatientWithIPPEmed");

    //Ajout de propriété: addProperty(nom de variable, valeur) -> Le nom de la variable vient du fichier WSDL
    request.addProperty("IPPEmed", Integer.parseInt("10640137"));
    request.addProperty("masque_de_donnee", Integer.parseInt("0"));

    //Toutes les données demandées sont mises dans une enveloppe.
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    //Préparation de la requête
    envelope.dotNet = true;
    envelope.encodingStyle = SoapSerializationEnvelope.ENC;
    envelope.setOutputSoapObject(request);

    HttpTransportSE androidHttpTransport = new HttpTransportSE("http://urlwebsite/service.asmx");
    //Ceci est optionnel, on l'utilise pour savoir si nous voulons ou non utiliser 
    //un paquet "sniffer" pour vérifier le message original (androidHttpTransport.requestDump)
    androidHttpTransport.debug = true; 
    //Envoi de la requête

    androidHttpTransport.call("http://webservicesobject.url.fr/GetPatientWithIPPEmed", envelope);
    //Obtention du résultat

    Object test = (Object)envelope.getResponse();
    SoapObject soapResult = (SoapObject)envelope.bodyIn;
    int nb = soapResult.getPropertyCount();

    return soapResult;

It runs like a charm for web-method simple like : - String GetVersion() - List GetAllRooms()

But for the methods with parameters like : - CRoom GetPatientWithIPPEmed(int IPPEmed, int masque_de_donnee)

The result of object test is null ! Of course if I call this method with IE I have an object ;).

However, i have this soap message :

<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><n0:GetPatientWithIPPEmed id="o0" c:root="1" xmlns:n0="http://webservicesobject.url.fr/"><IPPEmed i:type="d:int">10640137</IPPEmed>
<masque_de_donnee i:type="d:int">0</masque_de_donnee>
</n0:GetPatientWithIPPEmed></v:Body></v:Envelope>

Or the correct soap message must be :

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Body>
<GetPatientWithIPPEmed xmlns="http://webservicesobject.url.fr/">
<IPPEmed>10640137</IPPEmed>
<masque_de_donnee>0</masque_de_donnee>
</GetPatientWithIPPEmed>
</soap:Body>
</soap:Envelope>

the problem must be here I think :

<IPPEmed i:type="d:int">10640137</IPPEmed>
<masque_de_donnee i:type="d:int">0</masque_de_donnee>

but how can I generate the correct soap message ?


Solution

  • see here the simple example of ksoap may help refer