Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android WebService
Hello everyone,
 
I am calling a web service from android using ksoap2. However I am having a problem in sending complex type parameters. I have a wsdl which has a method "invokeservice" :
 
<message name="invokeService">
<part name="serviceName" type="xsd:string"/>
<part name="documents" type="tns:uriList"/>
<part name="literalDocs" type="ns1:stringArray"/>
<part name="connID" type="xsd:long"/>
<part name="gateParams" type="tns:gateRuntimeParameterArray"/>
<part name="userCtx" type="tns:userContext"/>
</message>
 
for the property "gateParams" which is of type "gateRuntimeParameterArray" , you have :
<xs:complexType name="gateRuntimeParameterArray" final="#all">
<xs:sequence>
<xs:element name="item" type="tns:gateRuntimeParameter" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
</xs:sequence>
</xs:complexType>
 
this "item" of type "gateRuntimeParameter" has :
<xs:complexType name="gateRuntimeParameter">
<xs:sequence>
<xs:element name="booleanValue" type="xs:boolean" minOccurs="0"/>
<xs:element name="corpusValue" type="xs:anyType" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="defaultValueString" type="xs:string" minOccurs="0"/>
<xs:element name="doubleValue" type="xs:double" minOccurs="0"/>
<xs:element name="intValue" type="xs:int" minOccurs="0"/>
<xs:element name="label" type="xs:string" minOccurs="0"/>
<xs:element name="optional" type="xs:boolean"/>
<xs:element name="PRName" type="xs:string" minOccurs="0"/>
<xs:element name="paramName" type="xs:string" minOccurs="0"/>
<xs:element name="pipelineName" type="xs:string" minOccurs="0"/>
<xs:element name="stringValue" type="xs:string" minOccurs="0"/>
<xs:element name="type" type="xs:string" minOccurs="0"/>
<xs:element name="urlValue" type="xs:anyURI" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
 
I created classes gateRuntimeParameter.java and "gateRuntimeParameterArray.java" which implement kvmserializable.
 
public class gateRuntimeParameterArray implements KvmSerializable{
 
    public gateRuntimeParameter[] item ;//= new gateRuntimeParameter[1];
    //public List<gateRuntimeParameter> item = new ArrayList<gateRuntimeParameter>();
    public void setItemArray(int index,gateRuntimeParameter value)
    {
        System.out.println("Filling array of gate params at "+index+" with value: "+value.prName);
        item[index] = value;
        //item.add(value);
        System.out.println("Filling is done ! "+item[index].defaultValueString);
    }
    @Override
    public Object getProperty(int arg0) {
        switch (arg0){
        case 0:
            return item;
        default:
            return null;
 
        }
    }
 
    @Override
    public int getPropertyCount() {
 
        return 1;
    }
 
    @Override
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
        switch(arg0)
        {
        case 0:
            arg2.type = gateRuntimeParameter.class;
            //arg2.type = uriList.getClass();
            arg2.name = "item";
            break;
 
        default:break;
        }
 
    }
 
    @Override
    public void setProperty(int arg0, Object arg1) {
        switch(arg0)
        {
        case 0:
 
            item = (gateRuntimeParameter[])arg1;
            //item = (List<GateRuntimeParameterArray>)arg1;

            break;
 
        default:
            break;
        }
 
    }
 
}
 

public class gateRuntimeParameter implements KvmSerializable 
{
//"prName", "paramName", "pipelineName", "stringValue", "type", "urlValue"})
public String defaultValueString;//defaultValueString=10; for example
public String label;//label=Number of search results; for example
public Boolean optional;//optional=true;
public String prName;//PRName=Yahoo PR;
public String paramName;//paramName=limit;
public String pipelineName;//pipelineName=Yahoo Search;
public String type;//type=int;

public Integer intValue;// how many results we want for yahoo PR for example
public Boolean booleanValue ;
public List<Object> corpusValue; //public Corpus corpusValue;
public Double doubleValue;
public String stringValue;
public String urlValue;
 
@Override
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return booleanValue;
case 1:
return corpusValue;
case 2:
return defaultValueString;
case 3:
return doubleValue;
case 4:
return intValue;
case 5:
return label;
case 6:
return optional;
case 7:
return prName;//maybe prName
case 8:
return paramName;
case 9:
return pipelineName;
case 10:
return stringValue;
case 11:
return type;
case 12:
return urlValue;
default:
return null;
}
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 13;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.BOOLEAN_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "booleanValue";
break;
case 1:
//arg2.type = List.class;//maybe here is the error
arg2.type = PropertyInfo.OBJECT_CLASS;//maybe here is the error
arg2.name = "corpusValue";
break;
case 2:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "defaultValueString";
break;
case 3:
arg2.type = Double.class;
//arg2.type = uriList.getClass();
arg2.name = "doubleValue";
break;
case 4:
arg2.type = PropertyInfo.INTEGER_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "intValue";
break;
case 5:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "label";
break;
case 6:
arg2.type = PropertyInfo.BOOLEAN_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "optional";
break;
case 7:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "PRName";
break;
case 8:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "paramName";
break;
case 9:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "pipelineName";
break;
case 10:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "stringValue";
break;
case 11:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "type";
break;
case 12:
arg2.type = PropertyInfo.STRING_CLASS;
//arg2.type = uriList.getClass();
arg2.name = "urlValue";
break;
 
default:break;
}
 
}
@Override
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
case 0:
booleanValue = (Boolean)arg1;
//Integer.parseInt(arg1.toString());
break;
case 1:
corpusValue = (List<Object>)arg1;
break;
case 2:
defaultValueString = (String)arg1;
break;
case 3:
doubleValue = (Double)arg1;
break;
case 4:
intValue = (Integer)arg1;
break;
case 5:
label = (String)arg1;
break;
case 6:
optional = (Boolean)arg1;
break;
case 7:
prName = (String)arg1;
break;
case 8:
paramName = (String)arg1;
break;
case 9:
pipelineName = (String)arg1;
break;
case 10:
stringValue = (String)arg1;
break;
case 11:
type = (String)arg1;
break;
case 12:
urlValue = (String)arg1;
break;
default:
break;
}
 
}
}
 
and I am doing:
 
gateRuntimeParameterArray gtParamArr = new gateRuntimeParameterArray();
 
gateRuntimeParameter gtRTparam = new gateRuntimeParameter();
 
Then I fill the gtRTparam, then I do following:
pi = new PropertyInfo();
pi.setName("gateParams");
pi.setValue(gtParamArr.item);
 
pi.setType(gateRuntimeParameterArray.class);
 
sobj.addProperty(pi);
 
and then I add mapping plus marshalling:
soapEnvelope.addMapping(namespace, gateRuntimeParameter.class.getSimpleName(), gateRuntimeParameter.class);
soapEnvelope.addMapping(namespace, gateRuntimeParameterArray.class.getSimpleName(), gateRuntimeParameterArray.class);
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(soapEnvelope);
 
However I keep getting Exception : Cannot serialize: [Lcom.example.NLPAndroid.gateRuntimeParamer;@44f05d38
 
I have been trying since 3 days, but can't understand what am i doing wrong? I have the following stack trace:
 
java.lang.RuntimeException: Cannot serialize: [Lcom.example.NLPAndroid.gateRuntimeParameter;@43e5ed38
    at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:629)
    at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:613)
    at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:582)
    at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:566)
    at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:623)
    at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:547)
    at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192)
    at org.ksoap2.transport.Transport.createRequestData(Transport.java:74)
    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:58)
    at com.example.NLPAndroid.KSoap2Test.invokeServicesTwo(KSoap2Test.java:419)
    at com.example.NLPAndroid.NLPAndroidTestServices.onCreate(NLPAndroidTestServices.java:27)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4627)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
 

I know I wrote a lot but please I need your help, I have a demo in a week and if this doesn't work, I won't be able to show anything Frown | :(
 
Thanks a lot.
Posted 16-Mar-11 12:36pm
chadic384
Edited 16-Mar-11 15:36pm
223.5K
v6
Comments
HimanshuJoshi at 16-Mar-11 20:50pm
   
Updated to correct pre tags.
jinshadb at 8-Jan-13 4:29am
   
Haii Chadic........., me too face the same problem. If you understand how to solve this issue please help me too

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 410
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Vinay Mistry 160
4 Sergey Alexandrovich Kryukov 138
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100