android ksoap2 中把XML(DataSet) 當做參數傳遞,androidksoap2
我的android app中需要發送webservice ,於是我使用了 ksop2 進行發送,在測試過程中不是很順利,不能正常工作.
我的web service 請求格式如下
[html] view plaincopy
- <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 如下
[java] view plaincopy
- 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 處理請求後變成這樣
[html] view plaincopy
- <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人 整理髮布,轉載須標明出處。