Webservice (SOAP) with complex data type and KSOAP Client

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby ramyaanmol » Mon Dec 06, 2010 11:37 pm

HI,
I am new to android. I want to call a webservice from android device.
Please upload the "full project" once again. There is some problem while downloading.
Regards
Ramya
ramyaanmol
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 06, 2010 7:10 pm

Top

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby shashankitmaster » Tue Dec 28, 2010 11:45 am

I am getting error of Out Of Memory Exception when using this code.

I am using Apache Axis Server of Web service.
Here is the code which gets Bean Array as response from web service.

Main Class from which web service it created.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class MultipleFilesImpl implements MultipleFiles {
  2. public FileData[] sendPDFs() {
  3.     FileData fileData = null;
  4.     // List<FileData> filesDetails = new ArrayList<FileData>();
  5.     File fileFolder = new File(
  6.             "C:/eclipse/workspace/AIPWebService/src/pdfs/");
  7.     // File fileTwo = new File(
  8.     // "C:/eclipse/workspace/AIPWebService/src/simple.pdf");
  9.  
  10.     File sendFiles[] = fileFolder.listFiles();
  11.     // sendFiles[0] = fileOne;
  12.     // sendFiles[1] = fileTwo;
  13.  
  14.     DataHandler handler = null;
  15.     char[] readLine = null;
  16.     byte[] data = null;
  17.     int offset = 0;
  18.     int numRead = 0;
  19.     InputStream stream = null;
  20.     FileOutputStream outputStream = null;
  21.     FileData[] filesData = null;
  22.     try {
  23.         System.out.println("Web Service Called Successfully");
  24.  
  25.         for (int i = 0; i < sendFiles.length; i++) {
  26.             handler = new DataHandler(new FileDataSource(sendFiles[i]));
  27.             fileData = new FileData();
  28.             data = new byte[(int) sendFiles[i].length()];
  29.             stream = handler.getInputStream();
  30.             while (offset < data.length
  31.                     && (numRead = stream.read(data, offset, data.length
  32.                             - offset)) >= 0) {
  33.                 offset += numRead;
  34.             }
  35.             readLine = Base64Coder.encode(data);
  36.             offset = 0;
  37.             numRead = 0;
  38.             System.out.println("'Reading File............................");
  39.             System.out.println("\n");
  40.             System.out.println(readLine);
  41.             System.out.println("Data Reading Successful");
  42.  
  43.             fileData.setFileName(sendFiles[i].getName());
  44.             fileData.setFileData(String.valueOf(readLine));
  45.  
  46.             readLine = null;
  47.             System.out.println("Data from bean " + fileData.getFileData());
  48.  
  49.             outputStream = new FileOutputStream("D:/"
  50.                     + sendFiles[i].getName());
  51.  
  52.             outputStream.write(Base64Coder.decode(fileData.getFileData()));
  53.  
  54.             outputStream.flush();
  55.             outputStream.close();
  56.             stream.close();
  57.             // FileData fileDetails = new FileData();
  58.             // fileDetails = fileData;
  59.             // filesDetails.add(fileData);
  60.             filesData = new FileData[(int) sendFiles[i].length()];
  61.         }
  62.         // return fileData;
  63.     } catch (FileNotFoundException e) {
  64.         e.printStackTrace();
  65.     } catch (IOException e) {
  66.         e.printStackTrace();
  67.     } catch (Exception e) {
  68.         e.printStackTrace();
  69.     }
  70.  
  71.     return filesData;
  72. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


The code which gets this array (Android Side)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.io.File;
  2. import java.io.FileOutputStream;
  3.  
  4. import org.ksoap2.SoapEnvelope;
  5. import org.ksoap2.serialization.SoapObject;
  6. import org.ksoap2.serialization.SoapSerializationEnvelope;
  7. import org.ksoap2.transport.AndroidHttpTransport;
  8.  
  9. import android.app.Activity;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.widget.TextView;
  13.  
  14. public class PDFActivity extends Activity {
  15.         private final String METHOD_NAME = "sendPDFs";
  16.         private final String NAMESPACE = "http://webservice.uks.com/";
  17.         private final String SOAP_ACTION = NAMESPACE + METHOD_NAME;
  18.         private final String URL = "http://192.168.1.123:8080/AIPWebService/services/MultipleFilesImpl";
  19.  
  20.         /** Called when the activity is first created. */
  21.         @Override
  22.         public void onCreate(Bundle savedInstanceState) {
  23.                 super.onCreate(savedInstanceState);
  24.                 setContentView(R.layout.main);
  25.                 // Base64 base64 = new Base64();
  26.                 TextView textViewOne = (TextView) findViewById(R.id.textViewOne);
  27.                 // TextView textViewTwo = (TextView) findViewById(R.id.textViewTwo);
  28.                 try {
  29.                         SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
  30.  
  31.                         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
  32.                                         SoapEnvelope.VER11);
  33.                         envelope.setOutputSoapObject(soapObject);
  34.  
  35.                         textViewOne.setText("Web Service Started");
  36.                         AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
  37.  
  38.                         httpTransport.call(SOAP_ACTION, envelope);
  39.  
  40.                         SoapObject result = (SoapObject) envelope.bodyIn;
  41.                         // Object result = envelope.getResponse();
  42.                         Log.i("Result", result.toString());
  43.  
  44.                         String[] values = new String[result.getPropertyCount()];
  45.  
  46.                         for (int i = 0; i < result.getPropertyCount(); i++) {
  47.                                 Log.i("Value", result.getProperty(i).toString());
  48.                         }
  49.                         // String fileName = result.getProperty("fileName").toString();
  50.                         // String fileData = result.getProperty("fileData").toString();
  51.  
  52.                         // Log.i("File Name", fileName);
  53.                         // Log.i("File Data", fileData);
  54.  
  55.                         // File pdfFile = new File(fileName);
  56.  
  57.                 // if(pdfFile)
  58.  
  59.                         // FileOutputStream outputStream =
  60.                         // openFileOutput(pdfFile.toString(),
  61.                         // MODE_PRIVATE);
  62.  
  63.                         // outputStream.write(Base64Coder.decode(fileData));
  64.                         Log.i("File", "File Created");
  65.                         // textViewTwo.setText(result);
  66.                         // Object result = envelope.getResponse();
  67.                         // FileOutputStream outputStream = openFileOutput(name, mode)
  68.  
  69.                 } catch (Exception e) {
  70.                         e.printStackTrace();
  71.                 }
  72.         }
  73. }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Please help me.
Thanks in Advance.
shashankitmaster
Freshman
Freshman
 
Posts: 5
Joined: Wed Dec 22, 2010 1:25 pm

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby andrija » Tue Feb 22, 2011 12:34 am

I have one question. When i call my web service,i need to send a xml message which has ds:Signature element for digital signatures. How can this be done? I haven't even figured how to send a xml document to my web service :( I've seen that ppl send soap objects with .addProperty adding info,but i really need to send xml message cuz of validating against xml schema on the server side.
andrija
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Feb 21, 2011 7:48 pm

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby misu_cosma@yahoo.com » Sun Jun 19, 2011 6:41 pm

Does anyone know how to receive images from a web service.

If yes,please post some code.

Thanks!
misu_cosma@yahoo.com
Freshman
Freshman
 
Posts: 7
Joined: Mon May 09, 2011 11:03 am

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby dali_ing » Fri Jul 01, 2011 11:47 am

Hi,
I'm trying to use you sample:Calling a Webservice using Android
When passing parameter i got SoapFault due to ClassCastException.
When i modify the WSDL and make getComplexDataRequest message without parameter
and remove the addProperties the code works fine.

Can you check please how to pass this parameters, i've been searching for two days but it didn't work .
Thanks
dwarka.damodaran wrote:Greetings to All !!!

I am new to Android and mobile plateform. My need was to call a webservice deployed in Jboss which accepts a complex input and responds back with a complex output. I searched tro the internet was not able to find a complete guide for the same. I would like to contribute this small tutorial,

Calling a Webservice using Android

Introduction
This tutorial talks about how to consume a webservice (in this case a service deployed into Jboss) from Android 2.2. For this purpose the following tools and SDK’s are used,
1. Android SDK 2.2
2. JDK 1.6
3. Eclipse 3.5 with Android Plug-in
4. Jboss 5.0
5. KSOAP2 2.4
Here kSOAP is a SOAP web service client library for constrained Java environments such as Applets or J2ME applications (CLDC / CDC / MIDP)

Organization of the Tutorial

Part1: About the Webservice (Only the WSDL part)
Part2: Calling the webservice with complex request object
Part3: Receiving a complex response object and parsing the same

Part1: About the Webservice (Only the WSDL part)
This Sample webservice has one operation with a complex input parameter and a complex output parameter. The following is the WSDL,

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.example.org/AndroidSampleWebservice/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="AndroidSampleWebservice"
targetNamespace="http://www.example.org/AndroidSampleWebservice/">
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.example.org/AndroidSampleWebservice/">


      <xsd:element name="complexInData" type="tns:inData"></xsd:element>
      <xsd:element name="ComplexOutData" type="tns:outData"></xsd:element>

      <xsd:complexType name="inData">
         <xsd:sequence>
            <xsd:element name="firstName" type="xsd:string"></xsd:element>
            <xsd:element name="lastName" type="xsd:string"></xsd:element>
         </xsd:sequence>
      </xsd:complexType>
   
      <xsd:complexType name="outData">
         <xsd:sequence>
            <xsd:element name="generalData" type="tns:gData"></xsd:element>
            <xsd:element name="addressData" type="tns:aData"></xsd:element>
            <xsd:element name="accountData" type="tns:acData"></xsd:element>
         </xsd:sequence>
      </xsd:complexType>
   
      <xsd:complexType name="gData">
         <xsd:sequence>
            <xsd:element name="firstName" type="xsd:string"></xsd:element>
            <xsd:element name="lastName" type="xsd:string"></xsd:element>
            <xsd:element name="age" type="xsd:string"></xsd:element>
            <xsd:element name="sex" type="xsd:string"></xsd:element>
         </xsd:sequence>
      </xsd:complexType>
   
      <xsd:complexType name="aData">
         <xsd:sequence>
            <xsd:element name="street1" type="xsd:string"></xsd:element>
            <xsd:element name="street2" type="xsd:string"></xsd:element>
            <xsd:element name="postBox" type="xsd:string"></xsd:element>
            <xsd:element name="state" type="xsd:string"></xsd:element>
            <xsd:element name="country" type="xsd:string"></xsd:element>
         </xsd:sequence>
      </xsd:complexType>
   
      <xsd:complexType name="acData">
         <xsd:sequence>
            <xsd:element name="accountno" type="xsd:string"></xsd:element>
            <xsd:element name="bank" type="xsd:string"></xsd:element>
            <xsd:element name="accounttype" type="xsd:string"></xsd:element>
            <xsd:element name="balance" type="xsd:string"></xsd:element>
         </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="getComplexDataRequest">
    <wsdl:part element="tns:complexInData" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="getComplexDataResponse">
    <wsdl:part element="tns:ComplexOutData" name="parameters"/>
  </wsdl:message>
  <wsdl:portType name="AndroidSampleWebservice">
    <wsdl:operation name="getComplexData">
      <wsdl:input message="tns:getComplexDataRequest"/>
      <wsdl:output message="tns:getComplexDataResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="AndroidSampleWebserviceSOAP" type="tns:AndroidSampleWebservice">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getComplexData">
      <soap:operation soapAction="http://www.example.org/AndroidSampleWebservice/getComplexData"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="AndroidSampleWebservice">
    <wsdl:port binding="tns:AndroidSampleWebserviceSOAP" name="AndroidSampleWebserviceSOAP">
      <soap:address location="http://<your ip and port>/"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>


From the webservice the following are clear,
Service Name: AndroidSampleWebservice
Operation: getComplexData
Input: getComplexDataRequest (A complex request)
Output: getComplexDataResponse (A complex response)

Part2: Calling the webservice with complex request object

The structure of the input is:
Code: Select all
<xsd:element name="complexInData" type="tns:inData"></xsd:element>
<xsd:complexType name="inData">
         <xsd:sequence>
            <xsd:element name="firstName" type="xsd:string"></xsd:element>
            <xsd:element name="lastName" type="xsd:string"></xsd:element>
         </xsd:sequence>
      </xsd:complexType>


Step1:
The first step would be constructing the SoapObject. The following code demonstrates the construction,

Code: Select all
private static final String NAMESPACE = "http://www.example.org/AndroidSampleWebservice/";
private static final String METHOD_NAME = "complexInData";
SoapObject loSoapObject = new SoapObject(NAMESPACE, METHOD_NAME);
//At this point our loSoapObject here refers to the inData complex type.
//After this we have to set the elements firstName and the lastName into the loSoapObject
loSoapObject.addProperty("firstName","Dwarka");
loSoapObject.addProperty("lastName","Damodaran");


Step2:
Now we have got the SoapObject after this point we would be creating a Soap envelop, putting the envelop into a HTTP transport and calling the required method in the service. In most of the cases the step 2 would remain the same.
The following is the code for it,

Code: Select all
private static final String SOAP_ACTION = "http://www.example.org/AndroidSampleWebservice/getComplexData";
private static final String URL = "http://172.25.108.49:8080/AndroidWebservice/AndroidSampleWebservice?wsdl";
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(loSoapObject);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);


With this we have called the webservice.

Part3: Receiving a complex response object and parsing the same
After Part2 the webservice implementation would do the required work and respond back with the data. Now this data is available in the envelop from the previous part. To extract the body out of the envelop the following has to be done,

SoapObject loresponse = (SoapObject) envelope.bodyIn;

Here since out response type is a complex type we are type casting it into a Soapobject. Now this object would represent the xml tag “outData” in the WSDL. From this loResponseObject we can then extract the aData or acData or the gData tags and in the similar way the inner tags. For doing the following see the following code,

Code: Select all
SoapObject logObject = (SoapObject)loresponse.getProperty("generalData");
SoapObject loaObject = (SoapObject)loresponse.getProperty("addressData");
SoapObject loacObject = (SoapObject)loresponse.getProperty("accountData");
Log.d("WS", "logObject: "+logObject);
Log.d("WS", "loaObject: "+loaObject);
Log.d("WS", "loacObject: "+loacObject);            
Log.d("WS", "firstName: "+logObject.getProperty("firstName"));
Log.d("WS", "lastName: "+logObject.getProperty("lastName"));
Log.d("WS", "age: "+logObject.getProperty("age"));
Log.d("WS", "sex: "+logObject.getProperty("sex"));


The following is the complete code for the example:

Code: Select all
package com.android.example;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class WebserviceConsumer extends Activity {
   /** Called when the activity is first created. */

   private static final String NAMESPACE = "http://www.example.org/AndroidSampleWebservice/";
   private static final String METHOD_NAME = "complexInData";
   private static final String SOAP_ACTION = "http://www.example.org/AndroidSampleWebservice/getComplexData";
   private static final String URL = "http://172.25.108.49:8080/AndroidWebservice/AndroidSampleWebservice?wsdl";

   @Override
   public void onCreate(Bundle savedInstanceState) {
      Log.d("WS", "Inside onCreate");

      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      Log
            .d("WS",
                  "--------------------- Webservice Part Begins ---------------------");
      Log.d("WS", "1. SoapObject Construction");

      SoapObject loSoapObject = new SoapObject(NAMESPACE, METHOD_NAME);

      // If this is not a direct type i.e. a primitive or string then you
      // have to construct another SoapObject and put in the place of the
      // obejct
      loSoapObject.addProperty("firstName", "Dwarka");
      loSoapObject.addProperty("lastName", "Damodaran");
      Log.d("WS", "Construction of SOAP Object End !!!");

      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11); // put all required data into a soap
                              // envelope
      Log.d("WS", "2. Envelop Created");
      envelope.setOutputSoapObject(loSoapObject); // prepare request
      Log.d("WS", "3. Request Into Envelop");
      AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
      Log.d("WS", "4. Transport Created");
      httpTransport.debug = true; // this is optional, use it if you don't
                           // want to use a packet sniffer to check
                           // what the sent message was
                           // (httpTransport.requestDump)
      Log.d("WS", "5. Transport Level to True");
      try {
         httpTransport.call(SOAP_ACTION, envelope);
         if (envelope != null)
         {
            SoapObject loresponse = (SoapObject) envelope.bodyIn;
            SoapObject logObject = (SoapObject)loresponse.getProperty("generalData");
            SoapObject loaObject = (SoapObject)loresponse.getProperty("addressData");
            SoapObject loacObject = (SoapObject)loresponse.getProperty("accountData");
            Log.d("WS", "logObject: "+logObject);
            Log.d("WS", "loaObject: "+loaObject);
            Log.d("WS", "loacObject: "+loacObject);
            
            Log.d("WS", "firstName: "+logObject.getProperty("firstName"));
            Log.d("WS", "lastName: "+logObject.getProperty("lastName"));
            Log.d("WS", "age: "+logObject.getProperty("age"));
            Log.d("WS", "sex: "+logObject.getProperty("sex"));
            
         }
         else
         {
            Log.d("WS", "Response Envelop Error");
         }

      } catch (IOException e) {
         e.printStackTrace();
      } catch (XmlPullParserException e) {
         e.printStackTrace();
      }
   }
}


If you need to work with the same, the following has to be done,

1. Generate a webservice using the WSDL that i have provided.
2. Deploy the webservice
3. Create a Android project
4. Use the activity code above.

The following are the references for this material,

http://www.javaworld.com/javaworld/jw-08-2002/jw-0823-wireless.html?page=1
http://www.javaworld.com/javaworld/jw-08-2002/jw-0823-wireless.html?page=1
http://developer.android.com/reference/android/app/ListActivity.html
http://supportforums.blackberry.com/t5/Java-Development/Example-of-KSoap2-Wrapper-classes/m-p/473088
http://www.codeproject.com/KB/webservices/CallWebServiceFromkSOAP.aspx
http://stackoverflow.com/questions/1052300/how-to-call-a-net-webservice-from-android-using-ksoap2
http://android.amberfog.com/?p=45
http://www.google.co.in/search?q=ksoap2+example&hl=en&ei=10xlTJKuIY3CcbessboK&start=10&sa=N
http://www.blackberryforums.com/developer-forum/155972-blackberry-ksoap2-tutorial.html
http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/102/The-Minimum-Steps-to-utilize-KSOAP2.aspx
dali_ing
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jul 01, 2011 10:21 am

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby Bharath2598 » Wed Jul 27, 2011 11:21 am

Hi To All

I want to send the Xml document to .net web service .For that i create one xml file by using Dom and create one object for that dom and send to my .net server .it throws error like this "07-27 15:45:34.086: INFO/System.out(435): error::::::::Cannot serialize: org.apache.harmony.xml.dom.DocumentImpl@44ee96a8"


This Is My code


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.io.InputStream;
  2. import java.io.StringWriter;
  3.  
  4. import javax.xml.parsers.DocumentBuilder;
  5. import javax.xml.parsers.DocumentBuilderFactory;
  6. import javax.xml.parsers.ParserConfigurationException;
  7. import javax.xml.transform.Transformer;
  8. import javax.xml.transform.TransformerConfigurationException;
  9. import javax.xml.transform.TransformerException;
  10. import javax.xml.transform.TransformerFactory;
  11. import javax.xml.transform.dom.DOMSource;
  12. import javax.xml.transform.stream.StreamResult;
  13.  
  14. import org.ksoap2.SoapEnvelope;
  15. import org.ksoap2.serialization.PropertyInfo;
  16. import org.ksoap2.serialization.SoapObject;
  17. import org.ksoap2.serialization.SoapPrimitive;
  18. import org.ksoap2.serialization.SoapSerializationEnvelope;
  19. import org.ksoap2.transport.HttpTransportSE;
  20. import org.w3c.dom.Document;
  21. import org.w3c.dom.Element;
  22.  
  23. import android.app.Activity;
  24. import android.os.Bundle;
  25. import android.view.View;
  26. import android.widget.Button;
  27. import android.widget.TextView;
  28.  
  29. public class BuildAndSend extends Activity {
  30.        
  31.         private static final String METHOD_NAME = "SaveXmlData";
  32.         private static final String NAMESPACE = "http://tempuri.org/";
  33.         private static final String URL = "http://192.168.0.51/WebServiceExample/Service.asmx";
  34.         final String SOAP_ACTION = "http://tempuri.org/SaveXmlData";
  35.         TextView tv;
  36.         Button send;
  37.         StringBuilder sb;
  38.         Document doc;
  39.         DOMSource source;
  40.         StringWriter writer ;
  41.         InputStream inputStream;
  42.     /** Called when the activity is first created. */
  43.         String[] input = {"Bharath,9177049351", "Ramu,9866727992"};
  44.     String[] line = new String[2];
  45.     @Override
  46.     public void onCreate(Bundle savedInstanceState) {
  47.         super.onCreate(savedInstanceState);
  48.         setContentView(R.layout.main);
  49.         sb = new StringBuilder();
  50.         tv=(TextView)findViewById(R.id.text);
  51.         send=(Button)findViewById(R.id.button1);
  52.         send.setOnClickListener(new View.OnClickListener() {
  53.                         public void onClick(View v) {
  54.                                 call();
  55.                         }
  56.                 });
  57.        
  58.         DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
  59.         DocumentBuilder builder;
  60.                 try {
  61.                         builder = factory.newDocumentBuilder();
  62.                         doc = builder.newDocument();
  63.                         Element root = doc.createElement("root");
  64.                         doc.appendChild(root);
  65.                 //Element memberList = doc.createElement("members");
  66.                // root.appendChild(memberList);
  67.                
  68.                 for (int i = 0; i < input.length; i++) {
  69.                 line = input[i].split(",");
  70.                
  71.                 Element member = doc.createElement("member");
  72.                 root.appendChild(member);
  73.                
  74.                 Element name = doc.createElement("name");
  75.                
  76.                 name.appendChild(doc.createTextNode(line[0]));
  77.                 member.appendChild(name);
  78.                
  79.                 Element phone = doc.createElement("phone");
  80.                 phone.appendChild(doc.createTextNode(line[1]));
  81.                 member.appendChild(phone);
  82.             }
  83.                        
  84.                 TransformerFactory tFact = TransformerFactory.newInstance();
  85.             Transformer trans;
  86.                        
  87.                                 try {
  88.                                         trans = tFact.newTransformer();
  89.                                         writer = new StringWriter();
  90.                                         StreamResult result = new StreamResult(writer);
  91.                                         source = new DOMSource(doc);
  92.                                         trans.transform(source, result);
  93.                                         System.out.println(writer.toString());
  94.                                          // call();
  95.                                 } catch (TransformerConfigurationException e) {
  96.                                         // TODO Auto-generated catch block
  97.                                         e.printStackTrace();
  98.                                 } catch (TransformerException e) {
  99.                                         // TODO Auto-generated catch block
  100.                                         e.printStackTrace();
  101.                                 }
  102.                        
  103.                 } catch (ParserConfigurationException e) {
  104.                         e.printStackTrace();
  105.                 }
  106.     }    
  107.     public void call() {
  108.        
  109.                         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  110.                 PropertyInfo p=new PropertyInfo();
  111.                 p.setName("XmlFile");
  112.                 p.setValue(doc);
  113.                 p.setType(Document.class);
  114.             request.addProperty(p);
  115.             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  116.             envelope.dotNet = true;
  117.             envelope.setOutputSoapObject(request);
  118.             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  119.            
  120.             try {
  121.             androidHttpTransport.call(SOAP_ACTION, envelope);  <span style="font-size: 150%; line-height: 116%;">//Here It Throws Error//</span>
  122.             SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
  123.             String resultData = result.toString();
  124.             sb.append(resultData + "\n");
  125.             } catch (Exception e) {
  126.             sb.append("Error:\n" + e.getMessage() + "\n");
  127.             System.out.println("error::::::::"+e.getMessage());
  128.             }
  129.  
  130.  
  131.         }
  132. }
Parsed in 0.053 seconds, using GeSHi 1.0.8.4




Please Help me how to do that
Bharath2598
Freshman
Freshman
 
Posts: 2
Joined: Wed Jul 27, 2011 11:10 am

Top

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby jhogue » Wed Aug 10, 2011 12:00 am

Thanks for the examples, very helpful
jhogue
Freshman
Freshman
 
Posts: 2
Joined: Tue Aug 09, 2011 11:28 pm

Re: Webservice (SOAP) with complex data type and KSOAP Clien

Postby roderick.barnes » Thu Oct 27, 2011 4:14 am

When sending or receiving complex parameters you should be aware of when to use the interface KVMSerializable. I write about this in my blog.

http://roderickbarnes.com/blog/droid-ch ... parameters

I hope this helps,
Roderick L. Barnes
roderick.barnes
Freshman
Freshman
 
Posts: 7
Joined: Thu Oct 27, 2011 4:08 am

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests