`
aijuans
  • 浏览: 1548817 次
社区版块
存档分类
最新评论

android ksoap2 中把XML(DataSet) 当做参数传递

阅读更多

我的android app中需要发送webservice ,于是我使用了 ksop2 进行发送,在测试过程中不是很顺利,不能正常工作.
我的web service 请求格式如下

 

 

[html] view plaincopy
 
  1. <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">  
  2.     
  3.     <Body>  
  4.     
  5.         <UpdateVehicleViaObj xmlns="http://tempuri.org/">  
  6.     
  7.             <userHash>[string?]</userHash>  
  8.     
  9.             <vehicleObject>  
  10.     
  11.                 <Colour xmlns="http://schemas.datacontract.org/2004/07/StockService">[string?]</Colour>  
  12.     
  13.                 <Comments xmlns="http://schemas.datacontract.org/2004/07/StockService">[string?]</Comments>  
  14.     
  15.                 <Condition xmlns="http://schemas.datacontract.org/2004/07/StockService">[string?]</Condition>                  
  16.     
  17.             </vehicleObject>  
  18.     
  19.         </UpdateVehicleViaObj>  
  20.     
  21.     </Body>  
  22. </Envelope>  


 

我在android 代码中使用 ksoap2 如下

 

 

[java] view plaincopy
 
  1. SoapObject request = new SoapObject("Namespace""methodname");  
  2.     
  3.   request.addProperty(properyObject);  
  4.    
  5.    
  6.    
  7.  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);  
  8.    
  9.    
  10.    
  11.         //SOAP is implemented in dotNet true/false.  
  12.     
  13.         envelope.dotNet = true;  
  14.     
  15.         MarshalDouble md = new MarshalDouble();  
  16.     
  17.         //envelope.implicitTypes = true;  
  18.     
  19.         envelope.implicitTypes = true;  
  20.     
  21.         md.register(envelope);  
  22.     
  23.         //Set request data into envelope and send request using HttpTransport  
  24.     
  25.         envelope.setOutputSoapObject(request);  
  26.     
  27.         HttpTransportSE androidHttpTransport = new HttpTransportSE(mInObj.getUrl(), networkTimeOut);  
  28.    
  29.    
  30.    
  31.         androidHttpTransport.debug= true;  
  32.     
  33.         androidHttpTransport.call(SoapAction, envelope,headerPropertyArrayList);  


ksop2 处理请求后变成这样

 

 

 

[html] view plaincopy
 
  1. <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><UpdateVehicleViaObj xmlns="http://tempuri.org/" id="o0" c:root="1"><userHash>B5B2FDF87E848946</userHash><vehicleObject><Colour>red</Colour><  
  2. &  
  3. <Comments >red</Comments ><<Condition >red</Condition ><</vehicleObject></UpdateVehicleViaObj></v:Body></v:Envelope>  


求救:

 

 

处理方法

 

看看官方的 ksoap2 文档
https://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#sending/receiving_array_of_complex_types_or_primitives

你可以创建一个实现marshable接口的类,并在类中添加其他属性

 


原文地址:http://www.itmmd.com/201412/296.html 
该文章由 萌萌的IT人 整理发布,转载须标明出处。

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics