Webservice (SOAP) with complex data type and KSOAP Client

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

Webservice (SOAP) with complex data type and KSOAP Client

Postby cbraun75 » Tue May 27, 2008 3:44 pm

Hi! Just have nothing found for this with complex types so I tried it on my own for 2 days. And there it is my solution. Maybe there are better ones then please write them to me. Thanxx!

[font=Arial Black]Tutorial Coldfusion 8 Webservice (SOAP) with ANDROID Client (KSOAP) and PHP Client (NUSOAP)[/font]

So I tried the KSOAP with the tutorials and codes from Lex and the ksoap library from tuxpan look at theGoogle Discussion

for a coldfusion webservice with soap (Ksoap for android)

[font=Arial Black]1. Coldfusion Webservice[/font]
The coldfusion webservice is made very easy:
Just download coldfusion for developer it's free and set up the internal webserver
Just administrate it with localhost:8500

After this you made a new folder in the wwwroot folder like mine is DA.
Then into this you make a folder ws_functions. Into this folder you save the test6.cfc componet (this is the webservice) the wsdl file is made automatically for you.

test6.cfc:
Code: Select all
<cfcomponent >
  <!---    Every CFC method published as a web service must have a returntype specified.
          If your web service does not return a value, set returntype="void".  --->
         
  <cffunction
      name="getMessage"
      access="remote"
      returnType="filename[]"
      output="false">
         
              <!---    Optional input parameters are not supported in web services. Therefore,
                  if you have any cfargument tags with the required attribute set to no,
                  the setting is ignored and the argument treated as required. --->
          <cfargument name="vname" type="string" required="yes">
          <cfargument name="nname" type="string" required="yes"> 
   
      
     <cfset var response = ArrayNew(1)>
     <cfset var temp = "">
    
     <cfobject component="filename" name="tempname">
     <cfset tempname.vname = arguments.vname>
     <cfset tempname.nname = arguments.nname>
     <cfset temp = ArrayAppend(response, tempname)>
    
      <!--- Hier loop um mehrere Angaben zu übertragen --->
    <cfloop index = "LoopCount" from = 1 to = 5 >
       <cfobject component="filename" name="tempname2">
       <cfset tempname2.vname = #LoopCount#>
       <cfset tempname2.nname = #LoopCount# >
       <cfset temp = ArrayAppend(response, tempname2)>
    </cfloop>
    
    
   <cfreturn response>
  </cffunction>

</cfcomponent>

This webservice needs 2 strings vname and nname which means first and lastname for the definition of the complex type which is the returntype you must make another component which is placed in the ws_functions folder called filename.cfc:

Code: Select all
<cfcomponent>
  <cfproperty name="vname" type="string">
  <cfproperty name="nname" type="string">
</cfcomponent>


2. PHP NUSOAP CLIENT
After this your webservice can be connected through a new coldfusion site or with php and nusoap - i tried the second and the first one.

The second one you need an xampp or lampp server. (I loaded it from http://www.apachefriends.org)
NuSoap you can load it from Sourceforge or other sites But becareful with php5! Because it implements a native soap lib and the client is called like the same from nusoap so you must download this for php5 and intall it into webfolder Modified Version Download for php5

Then just enter the following code which is a ltitle bit changed from this one Scott Nichol version little bit updated

PLEASE LOOK IN THE scripts for more COMMENTS ...

Code: Select all
<?php
// Important to set the nusoap lib into the webfolder
      require_once "nusoap/lib/nusoap.php";

      $params = array(
      'vname' => 'chris',
      'nname' => 'braun'
      );
      //Version zur Abfrage
      // ohne literal style = cfcomponent ohne document
// IMPORTANT IN VISTA DON'T TRY LOCALHOST ONLY IP IS GOOD! BECAUSE VISTA DON'T let you use webservice code at a local server don't ask me why
      $client = new soapclientnusoap("http://192.168.1.7:8500/DA/ws_functions/test6.cfc?wsdl", true);
// ! IMPORTANT i used the changed php 5 nusoap client so it's ... new saopclientnusoap !!! initialization
      // Check for an error
      $err = $client->getError();
      if ($err) {
          // Display the error
          echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
          // At this point, you know the call that follows will fail
      }
      // Call the SOAP method
      $result = $client->call('getMessage' ,$params );
      // Check for a fault
      if ($client->fault) {
          echo '<h2>Fault</h2><pre>';
          print_r($result);
          echo '</pre>';
      } else {
          // Check for errors
          $err = $client->getError();
          if ($err) {
              // Display the error
              echo '<h2>Error</h2><pre>' . $err . '</pre>';
          } else {
              // Display the result
              echo '<h2>Result</h2><pre>';
              print_r($result);
          echo '</pre>';
          }
      }
      // Display the request and response
      echo '<h2>Request</h2>';
      echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
      echo '<h2>Response</h2>';
      echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
      // Display the debug messages
      echo '<h2>Debug</h2>';
      echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';

?>


3. SOAP ENVELOPE RESPONSE
If you call this then you can see what the client sends to the server what he gets back from the server (SOAP ENvelope) This is what it looks like here: The Full Resonse of the SOAP coldfusion web service:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. HTTP/1.0 200 OK
  2. Date: Tue, 27 May 2008 14:17:38 GMT
  3. Content-Type: text/xml; charset=utf-8
  4. Connection: close
  5. Server: JRun Web Server
  6.  
  7. <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  8.  <soapenv:Body>
  9.   <ns1:getMessageResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://ws_functions.da">
  10.    <getMessageReturn soapenc:arrayType="ns1:Filename[6]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
  11.     <getMessageReturn xsi:type="ns1:Filename">
  12.      <nname xsi:type="xsd:string">braun</nname>
  13.      <vname xsi:type="xsd:string">chris</vname>
  14.     </getMessageReturn>
  15.     <getMessageReturn xsi:type="ns1:Filename">
  16.      <nname xsi:type="xsd:string">1</nname>
  17.      <vname xsi:type="xsd:string">1</vname>
  18.     </getMessageReturn>
  19.     <getMessageReturn xsi:type="ns1:Filename">
  20.      <nname xsi:type="xsd:string">2</nname>
  21.      <vname xsi:type="xsd:string">2</vname>
  22.     </getMessageReturn>
  23.     <getMessageReturn xsi:type="ns1:Filename">
  24.      <nname xsi:type="xsd:string">3</nname>
  25.      <vname xsi:type="xsd:string">3</vname>
  26.     </getMessageReturn>
  27.     <getMessageReturn xsi:type="ns1:Filename">
  28.      <nname xsi:type="xsd:string">4</nname>
  29.      <vname xsi:type="xsd:string">4</vname>
  30.     </getMessageReturn>
  31.     <getMessageReturn xsi:type="ns1:Filename">
  32.      <nname xsi:type="xsd:string">5</nname>
  33.      <vname xsi:type="xsd:string">5</vname>
  34.     </getMessageReturn>
  35.    </getMessageReturn>
  36.   </ns1:getMessageResponse>
  37.  </soapenv:Body>
  38. </soapenv:Envelope>
  39.  
Parsed in 0.008 seconds, using GeSHi 1.0.8.4


So you can see the complex type of filenmae has two strings in it vname and nname.

4. ANDROID CLIENT (KSOAP)
To get a client for android you must import first the ksoap library of tuxpan Download the full android project from Full Project and the modify the Main class like this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.android.test_ws_array;
  2.  
  3.  
  4. import java.io.IOException;
  5. import java.util.Vector;
  6. import org.apache.commons.httpclient.HttpClient;
  7. import org.apache.commons.httpclient.methods.PostMethod;
  8. import org.ksoap2.SoapEnvelope;
  9. import org.ksoap2.serialization.SoapObject;
  10. import org.ksoap2.serialization.SoapSerializationEnvelope;
  11. import org.ksoap2.transport.AndroidHttpTransport;
  12.  
  13. import android.app.Activity;
  14. import android.os.Bundle;
  15. import android.util.Log;
  16. import android.view.View;
  17. import android.view.View.OnClickListener;
  18. import android.widget.EditText;
  19. import android.widget.TextView;
  20.  
  21. public class test_ws_array extends Activity {
  22.     private static final String SOAP_ACTION = "getMessage";
  23.     private static final String METHOD_NAME = "getMessage";
  24.     private static final String NAMESPACE = "http://rpc.xml.coldfusion";
  25.     // !!!!! IMPORTANT!!!!! THE URL OF THE CoLDFUSION WEBSERVER NOT LOCALHOST BECAUSE LOCALHOST IS THE ANDROID EMULATOR !!!!!
  26.     private static final String URL = "http://192.168.1.7:8500/DA/ws_functions/test6.cfc?wsdl";
  27.    
  28.     /** Called when the activity is first created. */
  29.     @Override
  30.     public void onCreate(Bundle icicle) {
  31.         super.onCreate(icicle);
  32.         setContentView(R.layout.main);
  33.  
  34.         //CALL the web service method with the two parameters vname and nname
  35.         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  36.                 request.addProperty("vname", "Christian");
  37.                 request.addProperty("nname", "Braun");
  38.  
  39.         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  40.         envelope.setOutputSoapObject(request);
  41.         AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);                    
  42.         try {
  43.                 androidHttpTransport.call(SOAP_ACTION, envelope);
  44.                
  45.                 // Get the SAOP Envelope back and the extract the body
  46.                 SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
  47.                
  48.                 Vector XXXX = (Vector) resultsRequestSOAP.getProperty("getMessageReturn");
  49.                
  50.                 //Count of the arrays beneath starting from 0
  51.                 //You can see the buildup with the php site with nusoap http://localhost/DA/nusoapclient_test2.php
  52.                 int testat = XXXX.size();
  53.                
  54.                 // It depends on how many arrays we  have we can get to the attributs of one of them with get(0), get(1) ....
  55.                 SoapObject test = (SoapObject) XXXX.get(0);
  56.                
  57.                 //Get the attributes in the array
  58.                 String tem = (String) test.getProperty("vname");
  59.                 tem = tem + " " + (String) test.getProperty("nname");
  60.                
  61.                 //Just show it in a text area field called lblStatus
  62.                 ((TextView)findViewById(R.id.lblStatus)).setText(tem.toString());  
  63.                
  64.                
  65.                
  66.                 // with androidhttptransport you need a catch block
  67.  
  68.         } catch(Exception E) {
  69.                 ((TextView)findViewById(R.id.lblStatus)).setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());
  70.         }
  71.  
  72.     }
  73. }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


The layout.xml looks like this ...

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7.  
  8.     <TextView
  9.                 android:layout_width="wrap_content"
  10.                 android:layout_height="wrap_content"
  11.                 android:text="STATUS:"
  12.         />
  13.     <TextView android:id="@+id/lblStatus"
  14.                 android:layout_width="fill_parent"
  15.                 android:layout_height="fill_parent"
  16.                 android:text="... editing ..."
  17.         />
  18. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


So maybe someone can see if there is a better way to get the things out of the soap envelope? Then PLEASE tell me! Thanxx
cbraun75
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Jan 28, 2008 9:12 pm
Location: Munich

Top

Top tutorial!

Postby richi-rich » Wed Jun 11, 2008 8:33 pm

Hi Chris,

1) thanks for the example!

2) I get an "XmlPullParserException (id=830004343520)" if I try to call this Calulator Webservice

http://webservices.iter.dk/calculator.asmx?op=Add

May be you have an idea, what the problem is?

Here is my code:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. import android.app.Activity;
  3.  
  4. import android.os.Bundle;
  5.  
  6. import android.view.View;
  7.  
  8. import android.widget.Button;
  9.  
  10. import android.widget.EditText;
  11.  
  12.  
  13.  
  14. import org.ksoap2.SoapEnvelope;
  15.  
  16. import org.ksoap2.serialization.SoapObject;
  17.  
  18. import org.ksoap2.serialization.SoapSerializationEnvelope;
  19.  
  20. import org.ksoap2.transport.AndroidHttpTransport;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.         public class daypro_calc extends Activity {
  27.  
  28.                 private Button okButton;
  29.  
  30.                 private EditText mA;
  31.  
  32.                 private EditText mB;
  33.  
  34.                        
  35.  
  36.                 private static final String SOAP_ACTION = "http://www.iter.dk/webservices/calculator.asmx/Add";
  37.  
  38.                 private static final String METHOD_NAME = "Add";
  39.  
  40.                 private static final String NAMESPACE = "";
  41.  
  42.                 private static final String URL = "http://www.iter.dk/webservices/calculator.asmx";
  43.  
  44.            
  45.  
  46.             @Override
  47.  
  48.             protected void onCreate(Bundle icicle) {
  49.  
  50.                 super.onCreate(icicle);
  51.  
  52.                 setContentView(R.layout.daypro_calc);
  53.  
  54.                
  55.  
  56.                 okButton = (Button) findViewById(R.id.ok);         
  57.  
  58.                 okButton.setOnClickListener(new View.OnClickListener() {
  59.  
  60.  
  61.  
  62.                     public void onClick(View view) {
  63.  
  64.                         setResult(RESULT_OK);
  65.  
  66.                      
  67.  
  68.                         mymethod();
  69.  
  70.                     }          
  71.  
  72.                 });
  73.  
  74.  
  75.  
  76.             }
  77.  
  78.             public static void mymethod() {
  79.  
  80.                  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  81.  
  82.                  request.addProperty("intA", "3");
  83.  
  84.                  request.addProperty("intB", "4");
  85.  
  86.  
  87.  
  88.                  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  89.  
  90.                  envelope.dotNet = true;
  91.  
  92.                  envelope.setOutputSoapObject(request);
  93.  
  94.                  AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
  95.  
  96.  
  97.  
  98.                  try {
  99.  
  100.                          androidHttpTransport.call(SOAP_ACTION, envelope);
  101.  
  102.                  } catch (Exception e) {
  103.  
  104.                          e.printStackTrace();
  105.  
  106.                  }
  107.  
  108.             }
  109.  
  110.         }
  111.  
  112.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


richi-rich
richi-rich
Freshman
Freshman
 
Posts: 2
Joined: Wed Jun 11, 2008 8:18 pm

Postby cbraun75 » Thu Jun 12, 2008 8:07 am

If i call the webservice i have the problem that 0 is the result so they don't accept the properties

my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private static final String SOAP_ACTION = "http://www.iter.dk/webservices/calculator.asmx/Add";
  2.  
  3.     private static final String METHOD_NAME = "Add";
  4.  
  5.     private static final String NAMESPACE = "http://www.iter.dk/webservices/calculator.asmx";
  6.  
  7.     // !!!!! WICHTIG !!!!! IMMER NEUE IP EINTRAGEN DA SICH DIESE JEDESMAL AENDERT !!!!!
  8.  
  9.     // GREENDRIVE.CFC!!!
  10.  
  11.     private static final String URL = "http://webservices.iter.dk/calculator.asmx?wsdl";
  12.  
  13.    
  14.  
  15.     //Called when the activity is first created.
  16.  
  17.     @Override
  18.  
  19.     public void onCreate(Bundle icicle) {
  20.  
  21.         super.onCreate(icicle);
  22.  
  23.         setContentView(R.layout.testsoapservice);
  24.  
  25.        
  26.  
  27.                         //Buttons deaktiviert alles automatisch
  28.  
  29.                        
  30.  
  31.                 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  32.  
  33.                         request.addProperty("intA", 3);// username von Preferences abgeholt
  34.  
  35.                         request.addProperty("intB", 4);
  36.  
  37.  
  38.  
  39.        
  40.  
  41.                 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  42.  
  43.                 envelope.setOutputSoapObject(request);
  44.  
  45.                 AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (URL);                    
  46.  
  47.                 try {
  48.  
  49.                         androidHttpTransport.call(SOAP_ACTION, envelope);
  50.  
  51.                         //Parse Response
  52.  
  53.                         SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
  54.  
  55.                         //String xy = resultsRequestSOAP.getProperty(0).toString();
  56.  
  57.                         ((TextView)findViewById(R.id.lblStatus)).setText("Ganzes Rückagbeobjekt:\n"+resultsRequestSOAP.toString());
  58.  
  59.  
  60.  
  61.                        
  62.  
  63.                 } catch(Exception E) {
  64.  
  65.                        
  66.  
  67.                         ((TextView)findViewById(R.id.lblStatus)).setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());
  68.  
  69.                        
  70.  
  71.                 }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.     }  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


and it looks like that in the emulator see the file below - Maybe there's something with the calling and the properties wrong

Hope I could help you
Attachments
Unbenannt.jpg
File of the emulator
Unbenannt.jpg (57.64 KiB) Viewed 77104 times
cbraun75
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Jan 28, 2008 9:12 pm
Location: Munich

you arer the best - its working now!!!

Postby richi-rich » Thu Jun 12, 2008 9:22 pm

Thanks! I think the problem was the definition of namespace and URL, now its working well and I also get the right result!

Thank you for solving the problem! :D
richi-rich
Freshman
Freshman
 
Posts: 2
Joined: Wed Jun 11, 2008 8:18 pm

Postby phannguyen » Thu Aug 14, 2008 4:34 am

Hi richi-rich,

Please write code of Namespace and URL edit.

Thanks!
PhanNguyen
phannguyen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Thu Jul 17, 2008 7:37 am

Postby carspee » Tue Nov 11, 2008 8:48 pm

I'm trying to use ksoap but I receive the following error:

java.io.IOEXCeption: SSL handshake failure: Failure in SSL library, usually a protocol error
error:130770FC:SSL
routinesSSL23_GET_SERVER_HELLO:unknown protocol(extlibs/openssl-0.9.8.h/ssl/s23_cInt.c:585
0xaf58a238:0x00000000)

My code is below:
private static final String SOAP_ACTION = "urn:server#testCall";
private static final String METHOD_NAME = "testCall";
private static final String NAMESPACE = "urn:server";
private static final String URL = "http://192.168.16.69/test.php";
private Object resultRequestSOAP = null;


try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);

AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);


resultRequestSOAP = envelope.getResponse();
String[] results = (String[]) resultRequestSOAP;
tvStatus.setText( results[0]);

} catch (IllegalArgumentException e){
tvError.setText("Error in soap arg: " + e);
} catch (InterruptedIOException e){
tvError.setText("Error in soap interupt : " + e);
} catch (IOException e) {
tvError.setText("Error in soap io: " + e);
} catch (XmlPullParserException e) {
tvError.setText("Error in soap xml: " + e);

}

Any idea what this means?
carspee
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Nov 04, 2008 6:44 pm

Top

I have a problem with AndroidHttpTransport.

Postby cattivik » Sat Jan 03, 2009 11:09 pm

Hello!
I have a problem with AndroidHttpTransport.
If the URL is not reachable, because the server is down, AndroidHttpTransport don't thrown any Exception.
It is possible to insert a time out?
Please give me some example,
Thanks
cattivik
Freshman
Freshman
 
Posts: 5
Joined: Fri Sep 26, 2008 10:04 pm

Postby digitalspaghetti » Sun Jan 04, 2009 11:55 pm

Thank you very much for this! It worked a treat for me.
digitalspaghetti
Freshman
Freshman
 
Posts: 6
Joined: Sun Jan 04, 2009 11:52 pm

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

Postby desuvinodkumar » Thu Jul 02, 2009 12:04 pm

Hi
How to parse the soap Object response .......
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

Problem while calling the web services in android

Postby karthick » Thu Aug 06, 2009 1:11 pm

Problem while calling the web services in android.

To call web services in android I have done the following steps

1. Wrote the web service class in java and stored in apache axis. (in .jws format)


public class ADD2No
{
public int add(int a,int b)
{
return (a+b);
}

public int sub(int c,int d)
{
return (c-d);
}
}

2. Then is have tested the web service on web browser.

http://192.168.1.41:8081/axis/ADD2No.jws

I have got.

There is a Web Service here
Click to see the WSDL
in browser.
3. then I implement the service using core java and Ksoap2 library. Its working fine.

4. But I got error when I call the web service via android.

5. This is my code.

package com.example.SamWebService;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class WebServiceInAndroid extends Activity
{
/** Called when the activity is first created. */

/*
private static final String SOAP_ACTION = "HelloYou";
private static final String METHOD_NAME = "getHello";
private static final String NAMESPACE = "urn:HelloYou";
private static final String URL = "http://localhost/lab/service.php";
*/

private static final String SOAP_ACTION = "ADD2No";
private static final String METHOD_NAME = "add";
private static final String NAMESPACE = "urn:ADD2No";
private static final String URL = "http://elcserver:8081/axis/ADD2No.wsdl";


//private Object resultsRequestSOAP = null;


@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);

TextView tv = (TextView) findViewById(R.id.txt1);

setContentView(R.layout.main);

try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("a", 3);
request.addProperty("b", 4);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

try
{
androidHttpTransport.call(SOAP_ACTION, envelope);

//Parse Response

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;

//String xy = resultsRequestSOAP.getProperty(0).toString();

tv.setText("Ganzes Rückagbeobjekt:n"+resultsRequestSOAP.toString());




}

catch (Exception e)
{
e.printStackTrace();
}

}
catch(Exception e)
{
tv.setText("Error : " + e.getMessage());
}


}



}
6. I have tried lot of methods still I am getting the error.
“Your application has been stopped unexpectedly”

7. my application’s manifest file is

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.SamWebService"
android:versionCode="1"
android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".WebServiceInAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<uses-permission xmlns:android="http://schemas.android.com/apk/res/android" android:name="android.permission.INTERNET"></uses-permission>

<uses-sdk android:minSdkVersion="3" />
</manifest>

8. So give me solutions to overcome this problem and how to define the SOAP_NAME, METHOD_NAME, NAMESPACE and URL what they meant really.

9. Give me the step by step procedure to call apache axis web services from android.
hi i am here to share my knowledge
karthick
Freshman
Freshman
 
Posts: 3
Joined: Thu Aug 06, 2009 10:34 am

Postby rakesh1908 » Wed Sep 16, 2009 12:46 pm

Hi cbraun75 & rich-rich,

Thanks for the above example !

Its working fine with my web services, which are designed in java. But, when I run on "HTTS" (URL = "https://<IPAddress>:<ssl port>/MyTestService?wsdl"), it is giving me the following Exception


09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): javax.net.ssl.SSLException: Not trusted server certificate
09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:363)
09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:173)
09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:408)
09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.connect(HttpsURLConnection.java:151)
09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): at org.ksoap2.transport.ServiceConnectionSE.connect(Unknown Source)
09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): at org.ksoap2.transport.HttpTransportSE.call(Unknown Source)
09-16 16:02:24.906: INFO/WEBSERVICE EXCEPTION(959): at com.syntel.service.Home$2.onClick(Home.java:158)


please help me, it is urgent.
I tried with trust manager that does not validate certificate chains..
even though the problem was not solved..

thanks in advance.
rakesh1908
Freshman
Freshman
 
Posts: 2
Joined: Wed Apr 08, 2009 3:14 pm

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

Postby quanta » Mon Dec 21, 2009 3:34 pm

Hi,

I am a newbie to Android. I am trying to follow your above tutorial and got the following questions:

1. If I just want to try web services (SOAP, WSDL) with Android client, do I have to install Adobe Coldfusion?

2. Could you please provide me some details on installation and use of Coldfusion for your tutorial, please?

Thanks.
quanta
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 21, 2009 3:07 pm

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

Postby Droid123 » Wed Dec 23, 2009 12:44 am

quanta wrote:Hi,

I am a newbie to Android. I am trying to follow your above tutorial and got the following questions:

1. If I just want to try web services (SOAP, WSDL) with Android client, do I have to install Adobe Coldfusion?

2. Could you please provide me some details on installation and use of Coldfusion for your tutorial, please?

Thanks.


Do you have a working webserver?
Droid123
Experienced Developer
Experienced Developer
 
Posts: 77
Joined: Sat Nov 21, 2009 1:21 pm

Property always Null

Postby skvettn » Mon Feb 01, 2010 11:19 am

Hi, The value of the parameter is always null when i debug the webservice.
any tip on whats wrong?
heres my code:

Webservice:

[WebMethod]
[SoapRpcMethod]
public string WelcomeMessage(string msg)
{
return msg;
}

JavaCode:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public String GetWelcomeMessage() {
  2.  
  3.         String result = "";
  4.  
  5.                 SoapObject request = new SoapObject(NAMESPACE, METHOD_Welcome);
  6.  
  7.                 request.addProperty("msg","Hello");
  8.  
  9.                 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  10.  
  11.                 envelope.dotNet = true;
  12.  
  13.                 envelope.setOutputSoapObject(request);
  14.  
  15.                 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  16.  
  17.  
  18.  
  19.                 try
  20.  
  21.                 {
  22.  
  23.                 androidHttpTransport.call(WelcomeMessage_SOAP_ACTION, envelope);
  24.  
  25.                 result = (String)envelope.getResponse();
  26.  
  27.        
  28.  
  29.                 }
  30.  
  31.                 catch(Exception e)
  32.  
  33.                 {
  34.  
  35.                  
  36.  
  37.                 }
  38.  
  39.                 return result;
  40.  
  41.                 }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


well, fixed it...
removed dotNet = true... and the problem was resolved...
Using dotNet. 3.0 webservice...
skvettn
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Feb 01, 2010 11:06 am

Postby Bigbacon » Sun Feb 21, 2010 3:54 am

i can't get this to work with a .net 3.5 web service using android 1.5 SDK and the ksoap2...

viewtopic.php?p=36170#36170
Bigbacon
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Jan 18, 2010 1:43 pm

Top
Next

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests