2012-05-05 39 views
1

我想添加一個枚舉作爲Web服務請求的參數調用Web服務。 我用ksoap2在Android,但我得到了java.lang.RuntimeException:無法序列:未定義 時通枚舉 我實現枚舉遵循How to pass an enum value to wcf webservice(Fildor答案)得到的RuntimeException當通過ksoap2,機器人與通枚舉作爲參數

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

能否請你幫我解決這個問題呢? 非常感謝。

回答

0

哦,我得到了一個答案,因爲我用枚舉實現元帥是發生 這個問題。 當我把這個枚舉類和枚舉例如

enum DrivingLicenseTypeEnum 
{ 
    UNDEFINED, 
    NSURED_DRIVER_INJURED, 
    INSURED_PASSENGER_INJURED, 
    PARTY_DRIVER_INJURED, 
    PARTY_PASSENGER_INJURED, 
    THIRD_PARTY_INJURED, 
    INSURED_VEHICLE_DAMAGE, 
    PARTY_VEHICLE_DAMAGE, 
    ASSET 
} 

class DrivingLicenseTypeEnumClass implements Marshal 
{ 
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,new DrivingLicenseTypeEnumClass()); 
    } 

    public void writeInstance(XmlSerializer arg0, Object arg1) 
      throws IOException { 
     arg0.text(((DrivingLicenseTypeEnum)arg1).name()); 
    } 

} 

它正常工作。