Wednesday, April 3, 2013

Im having some trouble passing an enum in my wcf service


Im trying to parse this enum:



public enum ResponseFormat
{
XML,
JSON,
PDF,
}


in with ksoap2 to a wcf service. I tried using Marshal but im not sure if its correct.


I have a class called Format:



public class Format implements Marshal
{
public enum ResponseFormat
{
XML,
JSON,
PDF,;
}

public Object readInstance(XmlPullParser xpp, String string, String string1, PropertyInfo pi)
{
try
{
return ResponseFormat.valueOf(xpp.nextText());
}
catch(Exception e)
{
return null;
}
}

public void writeInstance(XmlSerializer xs, Object o)
{
try
{
xs.text(((ResponseFormat)o).name());
}
catch (Exception e)
{
}
}

public void register(SoapSerializationEnvelope sse)
{
sse.addMapping(sse.xsd, "ResponseFormat", ResponseFormat.class, new Format());
}
}


Then i called the wcf service like this:



try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("UserSessionToken", guid);
request.addProperty("Reference", "Nicolas");
request.addProperty("ResponseFormat", Format.ResponseFormat.JSON);
request.addProperty("Surname", "Tyler");
request.addProperty("Firstname", "Nicolas");
request.addProperty("IDNumber", "1234567890123");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.addMapping("http://schemas.datacontract.org/2004/07/SearchWorksAPI", "ResponseFormat", Format.ResponseFormat.JSON.getClass(), new Format());
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

androidHttpTransport.call(SOAP_ACTION + METHOD_NAME, envelope);
SoapObject response = (SoapObject)envelope.getResponse();

return response.toString();
}
catch (Exception e)
{
return null;
}


Im getting the exception:



There was an error reflecting type 'ResponseObjects.Person[]'.; at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)


It seems to me that there is something wrong with the serialization. Any ideas on whats wrong here?



.

forum.xda-developers.com

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...