aspose file tools*
The moose likes Android and the fly likes how to pass an array of strings as an argument to a web service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "how to pass an array of strings as an argument to a web service" Watch "how to pass an array of strings as an argument to a web service" New topic
Author

how to pass an array of strings as an argument to a web service

s kirby
Greenhorn

Joined: Sep 25, 2010
Posts: 3
I have a web service written for apache tomcat and axis2 that is
working. I can call it with my java client ok. But, when I'm using
the android emulator code I wrote (see below) I have the following
issues -

(1) Could someone tell me what may be the cause of the error
(SocketException) as seen in the subject line? The adb log tells me it
is line 54 (AndroidHttpTransport call) below. Note that I do have the
right IP in the code when I run it. And I did update the manifest.xml file for INTERNET connection.

(note: I saw somewhere that is an IPv4 versus and IPv6 issue, and that the android emulator doesn't support IPv6). Their solution was to add this to the code: System.setProperty("java.net.preferIPv6Addresses","false"); Has anyone else heard of this?

(2) the other issue I have is my web service expects one argument,
that is an array of 5 strings, and I can't figure out how to pass it
in without getting a serialization error. If you could point me to a
way to do this I would be grateful. (Note - as a test, I was trying
to call the web service from a firefox browser with something like
"http://(my IP):8080/axis2/services/MtkService/determineBestModel?
args=str1 str2 ... (here I need to give it an array of strings but
haven't figured out how to do so,
args0={"str1","str2","str3","str4","str5"} isn't working.


package com.thinrunner.mtk_android_client;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5
6 import java.io.*;
7
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
14 import android.widget.TextView;
15
16 public class AndroidWsClient extends Activity
17 {
18
19 private static final String METHOD_NAME="determineBestModel";
20 private static final String SOAP_ACTION="determineBestModel";
21 private static final String URL="(my ip):8080/axis2/services/
MtkService?wsdl";
22 private static final String NAMESPACE="urn:";

24 private TextView tv;
25
26 /** Called when the activity is first created. */
27 @Override
28 public void onCreate(Bundle savedInstanceState)
29 {
30
31 //display
32 super.onCreate(savedInstanceState);
33 setContentView(R.layout.main);
34 tv=(TextView)findViewById(R.id.message_text);
35
36 //create and initialize the SOAP object
37 SoapObject request = new
SoapObject(NAMESPACE,METHOD_NAME);
38
39 //initialize SOAP parameters to be passed to the web
service
40 // String []
loc_str_arr={"58.","-106.","mae","temp","coarse"};
41 // request.addProperty("args",loc_str_arr);
42
43 //create SOAP envelope and serialize web service XML
object
44 SoapSerializationEnvelope soapEnvelope = new
SoapSerializationEn velope(SoapEnvelope.VER11);

//bind SOAP request into SOAP envelope
47 soapEnvelope.setOutputSoapObject(request);
48
49 //create the http object
50 AndroidHttpTransport aht = new
AndroidHttpTransport(URL);
51 try{
52
53 //make the web service call
54 aht.call(SOAP_ACTION,soapEnvelope);
55
56 //extract the response from the web service object
57 Object result = soapEnvelope.getResponse();
58
59 //print out the response
60 //tv.setText("Results: " = result);
61 tv.setText(result.toString());

Thanks so much for any tips/pointers.

Take care,
Steve
Pritam Shah
Greenhorn

Joined: Jul 13, 2009
Posts: 25
s kirby wrote:I have a web service written for apache tomcat and axis2 that is
working. I can call it with my java client ok. ...
.
.
.
.
.

Thanks so much for any tips/pointers.

Take care,
Steve



I am looking for similar answer. How to pass string array as an argument to function. The webservice is WSDL on Php server. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to pass an array of strings as an argument to a web service