2

Possible Duplicate:
Android, sending XML via HTTP POST (SOAP)

How can I post request for SOAP service in android?

Please give me some example

Thank you for sharing knowledge to me

Community
  • 1
  • 1
JAL
  • 109
  • 6
  • check this http://stackoverflow.com/questions/12907683/android-httpclient-defaulthttpclient-httppost/12907782#comment17486368_12907782 This is a post method for soap service with json format – G_S Oct 17 '12 at 03:46
  • It might be help you,[http://android-devblog.blogspot.in/2010/06/soap-on-android.html] – subodh Oct 17 '12 at 04:32
  • Thank you for your responds to me, actually my soap service is there is no input parameters. It return one integer value. – JAL Oct 17 '12 at 04:54

1 Answers1

0

Use the KSoap library, this is a codesnippet from my project:

SoapObject soapObject = new SoapObject(NAMESPACE_NIST_IMPORT,
                METHOD_NAME_NIST_IMPORT);

        ImportNistFileReq nistReq = new ImportNistFileReq(nistFile);

        PropertyInfo pi = new PropertyInfo();
        pi.setName("req");
        pi.setValue(nistReq);
        pi.setType(nistReq.getClass());
        soapObject.addProperty(pi);


        SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        new MarshalBase64().register(soapSerializationEnvelope);

        soapSerializationEnvelope.setOutputSoapObject(soapObject);

        soapSerializationEnvelope.addMapping(NAMESPACE_NIST_IMPORT, "ImportNistFileReq", new ImportNistFileReq().getClass());


        soapSerializationEnvelope.dotNet = true;
        Object objectResult = null;

        try {
            HttpTransportSE httpTransportSE = new HttpTransportSE(
                    URL_NIST_IMPORT);

            httpTransportSE.debug = true;
            httpTransportSE.call(SOAP_ACTION_NIST_IMPORT, soapSerializationEnvelope);

            String host = httpTransportSE.getPath();
            Log.i("HOST: ", host);

            objectResult = (Object) soapSerializationEnvelope.getResponse();


        } catch (IOException e) {
            Log.e("IO: ", e.getMessage());
        } catch (XmlPullParserException e) {
            Log.e("XML: ", e.getMessage());
        }

This piece of code sends a NIST File represented as a byte array encoded as Byte64 to a Webservice. Request like this one should be called in a separated thread like an AsyncTask..

The constants:

  • NAMEPSPACE_NIST_IMPORT
  • METHOD_NAME_NIST_IMPORT
  • URL_NIST_IMPORT
  • SOAP_ACTION_NIST_IMPORT

Refers to the wsdl file provided by my .NET service. A great tutorial is this one. If something is unclear, just ask. Good luck.

Tobias Moe Thorstensen
  • 8,861
  • 16
  • 75
  • 143
  • sorry I'm a newbie in java and android. How can I know if I can post request the data in soap service and response it in my application? If I use your suggestion. – JAL Oct 17 '12 at 10:36
  • If you are a newbie, this is pretty hard way to start your programming career..I started out with the example on the link I provided in my post, just to check if I could post some data to the webservice. You should try that aswell. **How can I know if I can post request the data in soap service and response it in my application?** This is defined by the `wsdl` file. Look in this file : http://www.w3schools.com/webservices/tempconvert.asmx?WSDL which is the wsdl file for the example.. – Tobias Moe Thorstensen Oct 17 '12 at 11:16