how to use String[] as property object in SoapObject request

4016 views
Skip to first unread message

soulsieger

unread,
Mar 2, 2011, 10:48:08 AM3/2/11
to ksoap2-android
Hi,

I’m calling in an android project a java webservice which has String[]
as one of its parameter.
I want to pass String[] to SoapObject request in android project.
I'm using ksoap2 library and the Soap request in android project is
not accepting String[] as property object.
I used PropertyInfo class and Vector<String> to store the values and
was able to send the request to the webservice but it’s failing during
de-serialization of the SOAP request.
Please let me know if anyone has a solution for this issue.

Thanks.

Webservice client code in Android:

private Vector<String> mSkusOrder = new Vector<String>();

SoapObject request;

PropertyInfo pi = new PropertyInfo();
pi.setName("n0:skuSavedVector");
pi.setValue(mSkusOrder);
request.addProperty(pi);

Webservice Code:

/**
* Checks for duplicate item in a customer order.
*
* @param custId - Customer id corresponding with the order
* @param skuEntered - Sku entered by the customer
* @param skuSaved - String array contains all items in the
customer order.
* @return String - retunrs duplicate sku found in the order.
*
* @throws SQLException
*/
public String checkDuplicateSku(String custId, String skuEntered,
String[] skuSaved) throws SQLException
{

//

//

}


Manfred Moser

unread,
Mar 2, 2011, 5:51:00 PM3/2/11
to ksoap2-...@googlegroups.com
I cant answer in detail but you can basically either implement a marshaller or parse the soapobject array manually. I think there was a blog post linked towards that somewhere but I dont recall. I know Mark was going to document that on the wiki but he is busy too.. 

manfred

naresh pasnur

unread,
Mar 2, 2011, 5:59:54 PM3/2/11
to ksoap2-...@googlegroups.com
Thanks for your reply.
Do I need to parse the soapobject array in the java webservice ?
Also, what parameter should I use for the web service method instead of String[].

Please see the code snippet in short:

Java webservice:
public String getSku(String[] skuList)
{
//processing code
return result;
}

Webservice client in Android:
SoapObject request;
String[] mSkuList = new String[2];
mSkuList[0] = “123456″;
mSkuList[1] = “456789″;


PropertyInfo pi = new PropertyInfo();

pi.setName(“n0:skuList”);
pi.setValue(mSkuList);// not working
request.addProperty(pi);


Best Regards,

Naresh

Manfred Moser

unread,
Mar 2, 2011, 6:01:47 PM3/2/11
to ksoap2-...@googlegroups.com
Ok... do you want to submit a string array in the request or parse it out in the response.. 

naresh pasnur

unread,
Mar 2, 2011, 6:10:55 PM3/2/11
to ksoap2-...@googlegroups.com
I want to pass a string array in the request.

naresh pasnur

unread,
Mar 2, 2011, 6:24:22 PM3/2/11
to ksoap2-...@googlegroups.com
Just to make it clear I have mentioned my code below:  Thanks

Android webservice client :
import org.ksoap2.serialization.SoapObject;

SoapObject request;
request = new SoapObject(NAMESPACE, WEBSERV_METHOD);


String[] mSkuList = new String[2];
mSkuList[0] = "123456";
mSkuList[1] = "456789";

request.addProperty("n0:skuList", mSkuList);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (WEBSERV_URL);               
try {
   androidHttpTransport.call(SOAP_ACTION, envelope);
   result = (SoapObject) envelope.bodyIn;
}
catch(Exception e){
//
}


Java webservice:
public String getSku(String[] skuList)
{
//processing code
return result;
}


Manfred Moser

unread,
Mar 2, 2011, 7:37:21 PM3/2/11
to ksoap2-...@googlegroups.com
I have not done this before so I am guessing. I would just switch on debugging and see if the request is what you expect on the server first. (see the wiki how to debug)

Then see if that arrives on the server fine.

Then see how the response gets assembled and how it arrives..

Hope that helps.. 

manfred

PS: If anybody has done this it would be great if you could put it here or on the wiki.. 

On Wed, Mar 2, 2011 at 3:24 PM, naresh pasnur <naresh...@gmail.com> wrote:
Just to make it clear I have mentioned my code below:  Thanks

Android webservice client :
import org.ksoap2.serialization.SoapObject;

SoapObject request;
request = new SoapObject(NAMESPACE, WEBSERV_METHOD);


String[] mSkuList = new String[2mSkuList[0] = "123456";

naresh pasnur

unread,
Mar 2, 2011, 9:20:43 PM3/2/11
to ksoap2-...@googlegroups.com
Hi Manfred,

This is what I tried so far.


String[] mSkuList = new String[2]
mSkuList[0] = "123456";
mSkuList[1] = "456789";

request.addProperty("n0:skuList", mSkuList);// This doesn't work as it throws error over here.

Then I used Vector and PropertyInfo class


private Vector<String> mSkuList= new Vector<String>();

mSkuList.add("123456");
mSkuList.add("456789");


PropertyInfo pi = new PropertyInfo();

pi.setName("n0:skuList");
pi.setValue(
mSkuList

);
request.addProperty(pi);

//This works and the request reaches the webservice but it throws cannot be de-serialization error

What parameter should I use in the web service method instead of String[]  in order to use PropertyInfo and Vector<String> at the client side ?


Thanks,

naresh

 


On Wed, Mar 2, 2011 at 7:37 PM, Manfred Moser <mos...@gmail.com> wrote:
I have not done this before so I am guessing. I would just switch on debugging and see if the request is what you expect on the server first. (see the wiki how to debug)

Then see if that arrives on the server fine.

Then see how the response gets assembled and how it arrives..

Hope that helps.. 

manfred

PS: If anybody has done this it would be great if you could put it here or on the wiki.. 

On Wed, Mar 2, 2011 at 3:24 PM, naresh pasnur <naresh...@gmail.com> wrote:
Just to make it clear I have mentioned my code below:  Thanks

Android webservice client :
import org.ksoap2.serialization.SoapObject;

SoapObject request;
request = new SoapObject(NAMESPACE, WEBSERV_METHOD);

Manfred Moser

unread,
Mar 3, 2011, 2:56:04 AM3/3/11
to ksoap2-...@googlegroups.com
On Wed, Mar 2, 2011 at 6:20 PM, naresh pasnur <naresh...@gmail.com> wrote:
Hi Manfred,

This is what I tried so far.


String[] mSkuList = new String[2]
mSkuList[0] = "123456";
mSkuList[1] = "456789";

request.addProperty("n0:skuList", mSkuList);// This doesn't work as it throws error over here.

Then I used Vector and PropertyInfo class


private Vector<String> mSkuList= new Vector<String>();

mSkuList.add("123456");
mSkuList.add("456789");

PropertyInfo pi = new PropertyInfo();

pi.setName("n0:skuList");
pi.setValue(
mSkuList
);
request.addProperty(pi);

//This works and the request reaches the webservice but it throws cannot be de-serialization error

What parameter should I use in the web service method instead of String[]  in order to use PropertyInfo and Vector<String> at the client side ?


It all depends on what webservice stack you use... you will have to ask on the respective mailings list for that stack. As long as the request created by ksoap is as expected by the webservice (and as visible by the wsdl) you should be fine. At this stage ksoap seems to be doing the right thing from what you are saying.. 

naresh pasnur

unread,
Mar 3, 2011, 10:12:53 AM3/3/11
to ksoap2-...@googlegroups.com
Thanks Manfred.
I'm actually using Systinet wasp api. I'll try to email my problem to the mailing list in detail.

Regards,
Naresh

naresh pasnur

unread,
Mar 6, 2011, 6:09:01 PM3/6/11
to ksoap2-...@googlegroups.com
Hi Manfred,

I'm really having hard time getting this to work. Please help me with this one.
Do you have any working example of Marshalling a String[] ?

Thanks

My relevant code snippet:


Android webservice client :
import org.ksoap2.serialization.SoapObject;

SoapObject request;
request = new SoapObject(NAMESPACE, WEBSERV_METHOD);


String[] mSkuList = new String[2]
 
mSkuList[0] = "123456";
mSkuList[1] = "456789";

request.addProperty("n0:skuList", mSkuList);// throws error over here. Cannot serialize String[]


SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport (WEBSERV_URL);               
try {
   androidHttpTransport.call(SOAP_ACTION, envelope);
   result = (SoapObject) envelope.bodyIn;
}
catch(Exception e){
//
}


Java webservice:
public String getSku(String[] skuList)
{
//processing code
return result;


On Thu, Mar 3, 2011 at 2:56 AM, Manfred Moser <mos...@gmail.com> wrote:

Manfred Moser

unread,
Mar 6, 2011, 9:30:18 PM3/6/11
to ksoap2-...@googlegroups.com
Sorry... I do not have a marshalling example. I would have to write and test it myself. But I know others on the list have done it.

Personally I am just parsing the soapobjects in code manually and that works fine. You can always fall back to that.. 

manfred

naresh pasnur

unread,
Mar 7, 2011, 12:50:51 PM3/7/11
to ksoap2-...@googlegroups.com
Hi Manfred,

Do you have an working example of parsing soapobjects in code manually ?

Thanks,
Naresh

Manfred Moser

unread,
Mar 7, 2011, 1:45:36 PM3/7/11
to ksoap2-...@googlegroups.com
Yes... but not with me. Will supply some stuff on the wiki later this week.. 

manfred

Thomas Rykala

unread,
Mar 7, 2011, 5:08:53 PM3/7/11
to ksoap2-android
Hi Manfred,

Please please put also an example how to pass an array of ints in the
Soap Request. My undergraduate uni project depends on it and I can't
do it with current version of KSOAP2 because of constant serialization
errors :(

Basically I fail to send this:

request.addProperty("dataIndexIDs", new int[] {63, 62}); // throws
RuntimeException: Cannot serialize

I'm awaiting your prompt help.

Kind regards
Thomas

On Mar 7, 6:45 pm, Manfred Moser <mosa...@gmail.com> wrote:
> Yes... but not with me. Will supply some stuff on the wiki later this
> week..
>
> manfred
>
> On Mon, Mar 7, 2011 at 9:50 AM, naresh pasnur <nareshpas...@gmail.com>wrote:
>
> > Hi Manfred,
>
> > Do you have an working example of parsing soapobjects in code manually ?
>
> > Thanks,
> > Naresh
>
> > On Sun, Mar 6, 2011 at 9:30 PM, Manfred Moser <mosa...@gmail.com> wrote:
>
> >> Sorry... I do not have a marshalling example. I would have to write and
> >> test it myself. But I know others on the list have done it.
>
> >> Personally I am just parsing the soapobjects in code manually and that
> >> works fine. You can always fall back to that..
>
> >> manfred
>
> >> On Sun, Mar 6, 2011 at 3:09 PM, naresh pasnur <nareshpas...@gmail.com>wrote:
>
> >>> Hi Manfred,
>
> >>> I'm really having hard time getting this to work. Please help me with
> >>> this one.
> >>> Do you have any working example of Marshalling a String[] ?
>
> >>> Thanks
>
> >>> My relevant code snippet:
>
> >>> *Android webservice client :*
> >>> import org.ksoap2.serialization.SoapObject;
>
> >>> SoapObject request;
> >>> request = new SoapObject(NAMESPACE, WEBSERV_METHOD);
>
> >>> String[] mSkuList = new String[2]
>
> >>> mSkuList[0] = "123456";
> >>> mSkuList[1] = "456789";
>
> >>> request.addProperty("n0:skuList", mSkuList);*// throws error over here.
> >>> Cannot serialize String[]*
>
> >>> SoapSerializationEnvelope envelope = new
> >>> SoapSerializationEnvelope(SoapEnvelope.VER11);
> >>> envelope.setOutputSoapObject(request);
> >>> AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport
> >>> (WEBSERV_URL);
> >>> try {
> >>>    androidHttpTransport.call(SOAP_ACTION, envelope);
> >>>    result = (SoapObject) envelope.bodyIn;
> >>> }
> >>> catch(Exception e){
> >>> //
> >>> }
>
> >>> *Java webservice:*
> >>> public String getSku(String[] skuList)
> >>> {
> >>> //processing code
> >>> return result;
>
> >>> On Thu, Mar 3, 2011 at 2:56 AM, Manfred Moser <mosa...@gmail.com> wrote:
> >>>>> On Wed, Mar 2, 2011 at 7:37 PM, Manfred Moser <mosa...@gmail.com>wrote:
>
> >>>>>> I have not done this before so I am guessing. I would just switch on
> >>>>>> debugging and see if the request is what you expect on the server first.
> >>>>>> (see the wiki how to debug)
>
> >>>>>> Then see if that arrives on the server fine.
>
> >>>>>> Then see how the response gets assembled and how it arrives..
>
> >>>>>> Hope that helps..
>
> >>>>>> manfred
>
> >>>>>> PS: If anybody has done this it would be great if you could put it
> >>>>>> here or on the wiki..
>
> >>>>>> On Wed, Mar 2, 2011 at 3:24 PM, naresh pasnur <nareshpas...@gmail.com
> >>>>>> > wrote:
>
> >>>>>>> Just to make it clear I have mentioned my code below:  Thanks
>
> >>>>>>> *Android webservice client :*
> >>>>>>> import org.ksoap2.serialization.SoapObject;
>
> >>>>>>> SoapObject request;
> >>>>>>> request = new SoapObject(NAMESPACE, WEBSERV_METHOD);
>
> >>>>>>> String[] mSkuList = new String[2]
>
> >>>>>> mSkuList[0] = "123456";
> >>>>>>> mSkuList[1] = "456789";
>
> >>>>>>> request.addProperty("n0:skuList", mSkuList);
>
> >>>>>>> SoapSerializationEnvelope envelope = new
> >>>>>>> SoapSerializationEnvelope(SoapEnvelope.VER11);
> >>>>>>> envelope.setOutputSoapObject(request);
> >>>>>>> AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport
> >>>>>>> (WEBSERV_URL);
> >>>>>>> try {
> >>>>>>>    androidHttpTransport.call(SOAP_ACTION, envelope);
> >>>>>>>    result = (SoapObject) envelope.bodyIn;
> >>>>>>> }
> >>>>>>> catch(Exception e){
> >>>>>>> //
> >>>>>>> }
>
> >>>>>>> *Java webservice:*
> >>>>>>> public String getSku(String[] skuList)
> >>>>>>> {
> >>>>>>> //processing code
> >>>>>>> return result;
> >>>>>>> }
>
> >>>>>>> On Wed, Mar 2, 2011 at 6:10 PM, naresh pasnur <
> >>>>>>> nareshpas...@gmail.com> wrote:
>
> >>>>>>>> I want to pass a string array in the request.
>
> >>>>>>>> On Wed, Mar 2, 2011 at 6:01 PM, Manfred Moser <mosa...@gmail.com>wrote:
>
> >>>>>>>>> Ok... do you want to submit a string array in the request or parse
> >>>>>>>>> it out in the response..
>
> >>>>>>>>> On Wed, Mar 2, 2011 at 2:59 PM, naresh pasnur <
> >>>>>>>>> nareshpas...@gmail.com> wrote:
>
> >>>>>>>>>> Thanks for your reply.
> >>>>>>>>>> Do I need to parse the soapobject array in the java webservice ?
> >>>>>>>>>> Also, what parameter should I use for the web service method
> >>>>>>>>>> instead of String[].
>
> >>>>>>>>>> Please see the code snippet in short:
>
> >>>>>>>>>> *Java webservice:*
> >>>>>>>>>> public String getSku(String[] skuList)
> >>>>>>>>>> {
> >>>>>>>>>> //processing code
> >>>>>>>>>> return result;
> >>>>>>>>>> }
>
> >>>>>>>>>> *Webservice client in Android:*
> >>>>>>>>>> SoapObject request;
> >>>>>>>>>> String[] mSkuList = new String[2];
> >>>>>>>>>> mSkuList[0] = “123456″;
> >>>>>>>>>> mSkuList[1] = “456789″;
> >>>>>>>>>> PropertyInfo pi = new PropertyInfo();
> >>>>>>>>>> pi.setName(“n0:skuList”);
> >>>>>>>>>> pi.setValue(mSkuList);// not working
> >>>>>>>>>> request.addProperty(pi);
>
> >>>>>>>>>> Best Regards,
>
> >>>>>>>>>> Naresh
>

Manfred Moser

unread,
Mar 7, 2011, 5:22:58 PM3/7/11
to ksoap2-...@googlegroups.com
I dont have a snippet for that. Someone else will have to do that..  if you post a snippet to the mailing list I can put it on the wiki or give you access.. 

manfred

Thomas Rykala

unread,
Mar 7, 2011, 5:29:15 PM3/7/11
to ksoap2-android
Thank you, but do you know if it's possible at all? Will this be fixed
in a future release of Ksoap2?

Regarding the snippet: basically I want to send an array of ints
throught Ksoap2. I guess a snippet like below will suffice?

request.addProperty("dataIndexIDs", new int[] {63, 62});

if someone knows how to solve it please help me, because I'm at
complete loss.

Thanks
Thomas

On Mar 7, 10:22 pm, Manfred Moser <mosa...@gmail.com> wrote:
> I dont have a snippet for that. Someone else will have to do that..  if you
> post a snippet to the mailing list I can put it on the wiki or give you
> access..
>
> manfred
>

Manfred Moser

unread,
Mar 16, 2011, 3:41:43 PM3/16/11
to ksoap2-...@googlegroups.com
  • Features of future release depend on community contributions. It works for me and I have no need for fixes at the moment. But if you want to contribute something I will pull it in and release.. 
  • see the wiki for the marshalling example of string []
manfred

Gabriel G

unread,
Apr 5, 2011, 10:55:13 AM4/5/11
to ksoap2-android
Hi, I'm new in this Group, and I have similar problems you are talking
to...
I need to send and array of Strings and I have an error...
Is Ksoap2-Android enable to send complex types as Arrays?
Any Help? Any Link?

Regards

On 16 mar, 16:41, Manfred Moser <mosa...@gmail.com> wrote:
>    - Features of future release depend on community contributions. It works
>    for me and I have no need for fixes at the moment. But if you want to
>    contribute something I will pull it in and release..
>    - see the wiki for the marshalling example of string []
>
> manfred

PP

unread,
Apr 6, 2011, 6:50:24 AM4/6/11
to ksoap2-android


On 5 avr, 16:55, Gabriel G <gabriel...@gmail.com> wrote:
> Hi, I'm new in this Group, and I have similar problems you are talking
> to...
> I need to send and array of Strings and I have an error...
> Is Ksoap2-Android enable to send complex types as Arrays?
> Any Help? Any Link?
>
> Regards
>

If for example you have

1)in the WSDL the complex type associated to array of strings is
declared as StringArray (it must have some name !)

2) the name of the parameter in the request is theStrings

2) you know the namespace

3) you have an array of Strings to send
such as String[] myStrings= new String[]{"one","two",three"};

you should

-create a SoapObject with the name StringArray

- add to it properties named 'item' for each string

-finally add that SoapObject to the request :

Something like


SoapObject aux = new SoapObject(namespace, "StringArray");
for ( String s : myStrings)
aux.addProperty("item", s);
request.addProperty("theStrings", aux);

Cheers.

Gabriel G

unread,
Apr 6, 2011, 10:23:13 AM4/6/11
to ksoap2-android
Hi PP,

let me copy-paste my problem :)

DATA: "coleccion" is an object (myObject) extending SoapObject

SoapObject _client = new SoapObject("", "myWebService");
java.util.Vector _vector = new java.util.Vector();

if (coleccion != null) {
int _len = coleccion.length;
for (int _i = 0; _i < _len; _i++) {
_vector.add(coleccion[_i]);
}
}

_client.addProperty("coleccion", _vector);
SoapSerializationEnvelope _envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
_envelope.bodyOut = _client;

//Recently Add to TRY
_envelope.addMapping("", "myParam", new
myObject().getClass());

HttpTransportSE _ht = new
HttpTransportSE(Configuration.getWsUrl());
_ht.call("", _envelope);

//ERROR Line
SoapObject _ret = (SoapObject) _envelope.getResponse();
int _len = _ret.getPropertyCount();
BasicResponse _returned = new BasicResponse();
for (int _i = 0; _i < _len; _i++) {
_returned.setProperty(_i, _ret.getProperty(_i)); }
return _returned;

ERROR:
04-05 15:13:16.383: WARN/System.err(691): SoapFault - faultcode:
'soap:Server' faultstring: 'Fault occurred while processing.'
faultactor: 'null' detail: null


Is already a SoapObject....
any Idea?

PP

unread,
Apr 7, 2011, 6:40:31 AM4/7/11
to ksoap2-android


On 6 avr, 16:23, Gabriel G <gabriel...@gmail.com> wrote:
> Hi PP,
>
> let me copy-paste my problem :)
>
> DATA: "coleccion" is an object (myObject) extending SoapObject
>

> Is already a SoapObject....
> any Idea?
>

Hi,
I think your mistake is here

_client.addProperty("coleccion", _vector);

KSoap2 does not know how to serialize a vector ??? so forget about it

I guess that coleccion is an array since you call coleccion.length so
you should try
like I shown it above with an array of Strings :

//You must know the namespace an the name of the array of your
complextype (check in the WSDL)
SoapObject aux = new SoapObject(namespace, "XXXXArray");

for ( Object o : coleccion)
aux.addProperty("item", o); // item is important !!!!

_client.addProperty("coleccion",aux);

That should work, even if elements of coleccion extend SoapObject. I
do it here
by sending an array of UserDatum (id,action) and my WS returns me
an array of UserRecord (id, name, firstname....) . Both classes
UserDatum and UserRecord do extend
SoapObject in my code...



Cheers.





marco mourad

unread,
Sep 13, 2012, 1:35:10 PM9/13/12
to ksoap2-...@googlegroups.com
Hi
i have a different problem i want to pass an array inside another one such as in php :
//$result = $cnn->call($session, 'mobile.user_create', array($session, array('email' => 't4es...@mail.com', 'firstname' => 'xxx_firstname', 'lastname' => 'xxx_apilastname', 'password' => 'test1234', 'gender' => 1)));

my code is:
METHOD_NAME = "call";
                    request = new SoapObject(NAMESPACE, METHOD_NAME);                   
                    request.addProperty("sessionId",sessionID);
                    request.addProperty("resourcePath","mobile.user_create");
                                                              
                    SoapObject aux = new SoapObject("urn:Magento", "FixedArray");
                    aux.addProperty("sessionID",sessionID);
                    aux.addProperty("email","t4es...@mail.com");
                    aux.addProperty("firstname","irfan_firstname");
                    aux.addProperty("lastname","kadir_apilastname");
                    aux.addProperty("password","test1234");
                    aux.addProperty("dob","1988-11-11");
                    aux.addProperty("@userPhone","01901001122");
                    aux.addProperty("gender",1);                                                           
                   
                    SoapObject aux2 = new SoapObject("urn:Magento", "FixedArray");
                    aux2.addProperty("session_id",sessionID);                   
                    aux2.addProperty("params",aux);
                                                                                               
                    request.addProperty("args",aux2);
                   
                    SoapObject req = request;
                    SOAP_ACTION = "http://schemas.xmlsoap.org/wsdl/" + METHOD_NAME;
                    envelope.setOutputSoapObject(request);
                    androidHttpTransport.call(SOAP_ACTION , envelope);
                    SoapSerializationEnvelope env= envelope;
                   
                    Object obj = envelope.getResponse();
But it not work fine
can you help me ??
thanks
Marco

Wilson Zamarco

unread,
Mar 18, 2018, 6:50:22 PM3/18/18
to ksoap2-android
Fiz esta postagem, pode acessar que eu tentei explicar.

http://wilsonzamarco.blogspot.com.br/2018/03/webservice-soap-matriz-e-objetos.html
Reply all
Reply to author
Forward
0 new messages