1

我试图解析这个枚举:

public enum ResponseFormat
{
    XML,
    JSON,
    PDF,
}

与 ksoap2 一起进入 wcf 服务。我尝试使用Marshal但我不确定它是否正确。

我有一个名为 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());
}
}

然后我像这样调用 wcf 服务:

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;
}

我得到了例外:

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)

在我看来,序列化有问题。关于这里有什么问题的任何想法?

4

0 回答 0