2011-11-11 26 views
1

我在通過wsdl發送複雜類參數時遇到了異常。發送KSOAP中複雜參數的問題

在我的反應我得到這個日誌:

Exception: SoapFault - faultcode: 'S:Server' faultstring: 'javax.xml.bind.UnmarshalException - with linked exception:[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,471]Message: Element type "systemGenerated" must be followed by either attribute specifications, ">" or "/>".]' faultactor: 'null' detail: [email protected]:::::::::::::::::::::::::::::::::::0Access00000000 BuyLimitLimit02233.000000001000.00.00.0 
Response>>>>>>>in exceptionnnn>>>>>>>>>>S:Serverjavax.xml.bind.UnmarshalException - with linked exception:[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,471]Message: Element type "systemGenerated" must be followed by either attribute specifications, ">" or "/>".]javax.xml.bind.UnmarshalException - with linked exception:

這裏是我的代碼片段。請大家爲我提供一個解決方案。

  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 


      MarshalDouble md = new MarshalDouble();// **this class is made to parse the double values** 

      md.register(envelope); 

      SoapObject rpc = new SoapObject(serviceNamespace, "getTradeOrderTotal"); 

      envelope.dotNet = false; 

      envelope.setOutputSoapObject(rpc); 

      envelope.encodingStyle = SoapSerializationEnvelope.XSD; 



      envelope.addMapping(serviceNamespace, "MTradeOrder", new MTradeOrder().getClass()); 


      MTradeOrder mt = new MTradeOrder(); //This is my complex class implementing kvmserializable. 


     /* mt.portfolioName=AppScreen.name2; 
      mt.securityName=AppScreen.symbol11; // These are the parameters that i am setting to my complex class 
      mt.orderType=AppScreen.ordertype; 
      mt.priceType=AppScreen.Pricetype; 
      mt.quantityRequested=AppScreen.quantity1; 
      mt.orderTermName=ActiveTradeOrder.orderterm; 
      mt.limitPrice=AppScreen.limitprice;*/ 


      PropertyInfo pi = new PropertyInfo(); 
     // pi.type=MarshalDouble.class; 


      rpc.addProperty("arg0", new MTradeOrder()); 




      HttpTransportBasicAuth ht = new HttpTransportBasicAuth(serviceUrl, AppScreen.wsunS, AppScreen.wspwdS); 
      ht.debug = true; 

      String result; 
      try 
      { 

       ht.call(soapAction, envelope); 

       result = (envelope.getResponse()).toString(); 

       System.out.println("Request::::::dump::::::::::::::::::::::::::::: \n" + ht.requestDump); 

       System.out.println("Response>>>>>>>>>>>>>>>>> \n" + ht.responseDump); 


       UiApplication.getUiApplication().invokeLater(new Runnable() { 
        public void run() 
        { 
         Dialog.alert("Login Successful!"); 
        } 
       }); 

      } 
      catch (Exception ex) 
      { 
       result = ex.toString(); 
       System.out.println("Exception: " + result); 
       System.out.println("Request::::::::::::::::::::::::::::::::::: \n" + ht.requestDump); 
       System.out.println("Response>>>>>>>in exceptionnnn>>>>>>>>>> \n" + ht.responseDump); 
       UiApplication.getUiApplication().invokeLater(new Runnable() { 
        public void run() 
        { 
         Dialog.alert("Login Unsuccessful!\nPlease try again."); 
        } 
       }); 
      } 

     } 

回答

0

我覺得你確實應該發送的財產「PI」 &類的實例「噸」 [確保對象不爲空。即在您的行rpc.addProperty行中設置值。像這樣,

rpc.addProperty(pi, mt);

我一般做這種方式:



    String CLASS_NAME = "Complex object class name"; // set this according to your wsdl complex object name 
    PropertyInfo pi = new PropertyInfo(); 
    pi.name = (CLASS_NAME); 
    pi.type = mt.getClass(); // class instance used with get class 
    request.addProperty(pi, mt); // add the property 


    // finally add mapping 
    final SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    env.addMapping(NAMESPACE, CLASS_NAME, new MTradeOrder().getClass()); 

到這裏看看,它可能會幫助: Complex Objects and Ksoap2