2011-08-12 68 views
0
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="checkpoint"> 
    <SOAP-ENV:Body> 
     <ns1:getPedidoResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"> 
     <tabla xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:pedidos[1]"> 
      <item xsi:type="tns:pedidos"> 
       <ID_PEDIDO xsi:type="xsd:int">1</ID_PEDIDO> 
       <RUT_CLIENTE xsi:type="xsd:int">1234</RUT_CLIENTE> 
       <ID_PAQUETE xsi:type="xsd:int">1</ID_PAQUETE> 
       <RUT_EMPLEADO xsi:type="xsd:int">5678</RUT_EMPLEADO> 
       <DIRECCION xsi:type="xsd:string">la moenda</DIRECCION> 
       <LATITUD xsi:type="xsd:string">-33,44291</LATITUD> 
       <lONGITUD xsi:type="xsd:string">-70,65386</lONGITUD> 
       <ESTADO xsi:type="xsd:int">1</ESTADO> 
      </item> 
     </tabla> 
     </ns1:getPedidoResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

這是我的課:如何在PHP從Android的使用Web服務與KSOAP

public class Pedidos implements KvmSerializable { 
    public int ID_PEDIDO; 
    public int RUT_CLIENTE; 
    public int ID_PAQUETE; 
    public int RUT_EMPLEADO; 
    public String DIRECCION; 
    public String LATITUD; 
    public String lONGITUD; 
    public int ESTADO; 

    public Pedidos(){} 
     @Override 
     public Object getProperty(int arg0) { 
      switch (arg0){ 
       case 0: 
        return ID_PEDIDO; 
       case 1: 
        return RUT_CLIENTE; 
       case 2: 
        return ID_PAQUETE; 
       case 3: 
        return RUT_EMPLEADO; 
       case 4: 
        return DIRECCION; 
       case 5: 
        return LATITUD; 
       case 6: 
        return lONGITUD; 
       case 7: 
        return ESTADO; 
       default: 
        return null; 
      } 
     } 

     @Override 
     public int getPropertyCount() { 
      return 7; 
     } 

     @Override 
     public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { 
      switch (arg0){ 
       case 0: 
        arg2.type = PropertyInfo.INTEGER_CLASS; 
        arg2.name = "ID_PEDIDO"; 
        break; 
       case 1: 
        arg2.type = PropertyInfo.INTEGER_CLASS; 
        arg2.name = "RUT_CLIENTE"; 
        break; 
       case 2: 
        arg2.type = PropertyInfo.INTEGER_CLASS; 
        arg2.name = "ID_PAQUETE"; 
        break; 
       case 3: 
        arg2.type = PropertyInfo.INTEGER_CLASS; 
        arg2.name = "RUT_EMPLEADO"; 
        break; 
       case 4: 
        arg2.type = PropertyInfo.STRING_CLASS; 
        arg2.name = "DIRECCION"; 
        break; 
       case 5: 
        arg2.type = PropertyInfo.STRING_CLASS; 
        arg2.name = "LATITUD"; 
        break; 
       case 6: 
        arg2.type = PropertyInfo.STRING_CLASS; 
        arg2.name = "lONGITUD"; 
        break; 
       case 7: 
        arg2.type = PropertyInfo.INTEGER_CLASS; 
        arg2.name = "ESTADO"; 
        break; 
       default: 
        break; 
      } 
     } 


     @Override 
     public void setProperty(int arg0, Object arg1) { 
      switch(arg0){ 
       case 0: 
        ID_PEDIDO = Integer.parseInt(arg1.toString()); 
        break; 
       case 1: 
        RUT_CLIENTE = Integer.parseInt(arg1.toString()); 
       case 2: 
        ID_PAQUETE = Integer.parseInt(arg1.toString()); 
       case 3: 
        RUT_EMPLEADO = Integer.parseInt(arg1.toString()); 
       case 4: 
        DIRECCION = arg1.toString(); 
       case 5: 
        LATITUD = arg1.toString(); 
       case 6: 
        lONGITUD = arg1.toString(); 
       case 7: 
        ESTADO = Integer.parseInt(arg1.toString()); 
       default: 
      } 
     } 
} 

這裏我撥打電話:

public class MainActivity extends Activity { 
    static final String SOAP_ACTION="http://192.168.117.1/ws_checkpoint.php/getPedido"; 
    static final String METHOD_NAME="getPedido"; 
    static final String NAMESPACE="checkpoint"; 
    static final String URL="http://192.168.117.1/ws_checkpoint.php"; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
     request.addProperty("pRutEmpleado",5678); 
     SoapObject result; 

     HttpTransportSE httpt = new HttpTransportSE(URL); 
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.addMapping(NAMESPACE, "checkpoint", Pedidos.class); 
     envelope.dotNet = false; 
     envelope.bodyOut = request; 

     try 
     { 
      httpt.debug = true; 
      httpt.call(SOAP_ACTION, envelope); 
      result = (SoapObject)envelope.bodyIn; 

      Vector<Pedidos> result_array = (Vector<Pedidos>)envelope.getResponse(); 

      if(result_array != null){ 
       for (Pedidos current_crop: result_array){ 
        System.out.println(current_crop.RUT_EMPLEADO); 
       } 
      } 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     }  
    } 
} 

的錯誤是:

java.lang.ClassCastException: org.ksoap2.serialization.SoapObject 

當我試圖打印current_crop.RUT_EMPLEADO

+0

你不能正確發送字段我想檢查這個字段,request.addProperty(「pRutEmpleado」,5678); – Randroid

回答

相關問題