I need to pass a List<string> or List<object>
to consume WCF soap service from Android. I have tried a lot of ways.
When i used below code:
public class MarshalArray implements Marshal{
@Override
public Object readInstance(XmlPullParser parser, String namespace, String name,
PropertyInfo expected) throws IOException, XmlPullParserException {
return GenericType.getObject(parser.nextText());
}
@Override
public void register(SoapSerializationEnvelope envelope) {
envelope.addMapping("http://schemas.datacontract.org/2004/07/WcfService1", "GenericType", GenericType.class, this);
}
@Override
public void writeInstance(XmlSerializer writer, Object obj)
throws IOException {
GenericType sp = (GenericType) obj;
writer.startTag("http://schemas.datacontract.org/2004/07/WcfService1", "mydata");
for(String str : sp.mydata){
writer.startTag("http://schemas.datacontract.org/2004/07/WcfService1", "string");
writer.text(str);
writer.endTag("http://schemas.datacontract.org/2004/07/WcfService1", "string");
}
writer.endTag("http://schemas.datacontract.org/2004/07/WcfService1", "mydata");
}}
With below wcf service:
[ServiceContract]
[ServiceKnownType(typeof(WcfService1.GenericType<string>))]
public interface IService1
{
[OperationContract]
[ServiceKnownType(typeof(WcfService1.GenericType<string>))]
string GetDataList(GenericType<string> objs);
}
[DataContract(Name = "GenericType")]
public class GenericType<T>
{
List<T> data;
[DataMember]
public List<T> mydata
{
get { return data; }
set { data = value; }
}
}
Wcf service return a soap fault error like: Internal service error..
Then I tried in another way:
public class Members extends Vector<String> implements KvmSerializable {
private static final long serialVersionUID = -1166006770093411055L;
@Override
public Object getProperty(int index) {
return this.get(index);
}
@Override
public int getPropertyCount() {
return this.size();
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo param) {
param.name = "String";
param.type = PropertyInfo.STRING_CLASS;
}
@Override
public void setProperty(int arg0, Object obj) {
this.add(obj.toString());
}
}
With below wcf service:
[ServiceContract]
public interface IService1 {
[OperationContract]
string GetDataList(List<string> objs);
}
I got soap fault error which return from wcf service:
Deserialization fail...
Every time I got an error from wcf service .. I think my wcf
service got something wrong.
If somebody know the answer .. please kindly answer my question.
Thanks awfully...
Finally I got the answer...
I decided used MarshalArray class, not Members(KvmSerializable).
While using MarshalArray, the problem is in MarshalArray class in android..
here is the old code that occur error:
for(String str : sp.mydata){
writer.startTag("http://schemas.datacontract.org/2004/07/WcfService1", "string");
writer.text(str);
writer.endTag("http://schemas.datacontract.org/2004/07/WcfService1", "string");
}
I changed it to like below:
for(String str:gt.mydata){
writer.startTag("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string");
writer.text(str);
writer.endTag("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string");
}
Then it works successfully...
Thanks for your help, stepoverflow. I had to find out the answer myself.... !!