码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-12-27 20:33:35      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:android   android开发   

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

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
  
    <Body>
  
        <UpdateVehicleViaObj xmlns="http://tempuri.org/">
  
            <userHash>[string?]</userHash>
  
            <vehicleObject>
  
                <Colour xmlns="http://schemas.datacontract.org/2004/07/StockService">[string?]</Colour>
  
                <Comments xmlns="http://schemas.datacontract.org/2004/07/StockService">[string?]</Comments>
  
                <Condition xmlns="http://schemas.datacontract.org/2004/07/StockService">[string?]</Condition>                
  
            </vehicleObject>
  
        </UpdateVehicleViaObj>
  
    </Body>
</Envelope>


我在android 代码中使用 ksoap2 如下

SoapObject request = new SoapObject("Namespace", "methodname");
  
  request.addProperty(properyObject);
 
 
 
 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
 
 
 
        //SOAP is implemented in dotNet true/false.
  
        envelope.dotNet = true;
  
        MarshalDouble md = new MarshalDouble();
  
        //envelope.implicitTypes = true;
  
        envelope.implicitTypes = true;
  
        md.register(envelope);
  
        //Set request data into envelope and send request using HttpTransport
  
        envelope.setOutputSoapObject(request);
  
        HttpTransportSE androidHttpTransport = new HttpTransportSE(mInObj.getUrl(), networkTimeOut);
 
 
 
        androidHttpTransport.debug= true;
  
        androidHttpTransport.call(SoapAction, envelope,headerPropertyArrayList);


ksop2 处理请求后变成这样

<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><
&
<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人 整理发布,转载须标明出处。

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

标签:android   android开发   

原文地址:http://blog.csdn.net/androidmylove/article/details/42195681

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!