我想添加一个枚举作为 Web 服务请求的参数。我在android上使用ksoap2,但我得到java.lang.RuntimeException:无法序列化: 通过枚举时未定义我实现枚举遵循如何将枚举值传递给wcf webservice(Fildor回答)
interface BaseEnum extends Marshal
{
public String getDesc(Enum en);
}
enum DrivingLicenseTypeEnum implements BaseEnum
{
UNDEFINED,
NSURED_DRIVER_INJURED,
INSURED_PASSENGER_INJURED,
PARTY_DRIVER_INJURED,
PARTY_PASSENGER_INJURED,
THIRD_PARTY_INJURED,
INSURED_VEHICLE_DAMAGE,
PARTY_VEHICLE_DAMAGE,
ASSET;
public String getDesc(Enum en) {
String result="";
//generate description
return result;
}
public Object readInstance(XmlPullParser arg0, String arg1, String arg2,
PropertyInfo arg3) throws IOException, XmlPullParserException {
// TODO Auto-generated method stub
return DrivingLicenseTypeEnum.valueOf(arg0.nextText());
}
public void register(SoapSerializationEnvelope arg0) {
arg0.addMapping("http://tempuri.org/", "DrivingLicenseTypeEnum", DrivingLicenseTypeEnum.class);
}
public void writeInstance(XmlSerializer arg0, Object arg1)
throws IOException {
arg0.text(((DrivingLicenseTypeEnum)arg1).name());
}
}
我通过 DrivingLicenseTypeEnum 作为参数传递
DrivingLicenseTypeEnum c = DrivingLicenseTypeEnum.UNDEFINED;
PropertyInfo pi=new PropertyInfo();
pi.setName("driverLicenseType");
pi.setValue(c);
pi.setType(DrivingLicenseTypeEnum.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
c.register(envelope);
你能帮我解决这个问题吗?非常感谢你。