Comment utiliser KSoap 2 sur android

Je viens de tombé sur de ksoap2 à l'aide de mon propre asp .net, webservices dans les applications android.
J'ai trouvé quelques grandes ressources sur internet et j'ai mis en place mon webservice dans l'application android.

Suivant est le webservice de la réponse que j'ai consommé:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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>
    <CheckAuthenticationResponse xmlns="http://tempuri.org/">
      <CheckAuthenticationResult>boolean</CheckAuthenticationResult>
    </CheckAuthenticationResponse>
  </soap:Body>
</soap:Envelope>

Pour consommer le service ci-dessus, j'ai mis en place le code suivant:

public static Boolean isAuthenticated(String UserName, String Password)
{
    String NAMESPACE = "http://tempuri.org/";
    String METHOD_NAME = "CheckAuthentication";
    String SOAP_ACTION = "http://tempuri.org/CheckAuthentication";
    String URL = "http://primehangout.com/primehangoutweb.asmx";

    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
    PropertyInfo pi = new PropertyInfo();
    pi.setName("UserId");
    pi.setValue(UserName);
    pi.setType(String.class);
    Request.addProperty(pi);

    PropertyInfo pi2 = new PropertyInfo();
    pi2.setName("Password");
    pi2.setValue(Password);
    pi2.setType(String.class);
    Request.addProperty(pi2);


    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(Request);
    try
    {
    AndroidHttpTransport transp = new AndroidHttpTransport(URL);
    transp.call(SOAP_ACTION, envelope);
    SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

    return Boolean.parseBoolean(result.toString());
    }
    catch(Exception e)
    {

    }


    return false;
}

Ça fonctionne..
Mais maintenant, je vais consommer un service.
Le service requis est le format de la requête est le suivant:

POST /primehangoutweb.asmx HTTP/1.1
Host: primehangout.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetComment"

<?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:Header>
    <AuthSoapHd xmlns="http://tempuri.org/">
      <strUserName>string</strUserName>
      <strPassword>string</strPassword>
    </AuthSoapHd>
  </soap:Header>
  <soap:Body>
    <GetComment xmlns="http://tempuri.org/">
      <UId>string</UId>
      <refID>int</refID>
    </GetComment>
  </soap:Body>
</soap:Envelope>

Et la réponse de service souhaité est le suivant:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

    <?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>
        <GetCommentResponse xmlns="http://tempuri.org/">
          <GetCommentResult>
            <xsd:schema>schema</xsd:schema>xml</GetCommentResult>
        </GetCommentResponse>
      </soap:Body>
    </soap:Envelope>

J'ai consommé les mêmes services dans mon précédent application iPhone à l'aide XMLReader les classes, mais comme je suis novice sur android, j'ai besoin de votre aide les gars.

🙂

Merci à tous pour la lecture de mon post!

vous pouvez voir ma réponse complète (stackoverflow.com/questions/51255957/...) pour les mêmes

OriginalL'auteur necixy | 2011-03-01