我在wcf服务中传递枚举时遇到了一些麻烦

时间:2013-04-03 06:16:30

标签: android eclipse wcf enums ksoap2

我试图解析这个枚举:

public enum ResponseFormat
{
    XML,
    JSON,
    PDF,
}

使用kso​​ap2到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)

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

0 个答案:

没有答案