1
我對這個Ksoap webservice調用很陌生。我知道如何從webservice調用中檢索數據,但是如何發送Object的ArrayList。通過Ksoap2發送ArrayList <object>以訪問用java編寫的Web服務
我的web服務是如下:
<message name="InsertBrandOrder">
<part name="Token" type="xsd:string"/>
<part name="UserID" type="xsd:int"/>
<part name="StoreID" type="xsd:int"/>
<part name="BrandOrders" type="ns1:anyTypeArray"/>
</message>
<message name="InsertBrandOrderResponse">
<part name="ResponseInsertBrandOrder" type="tns:result"/>
</message>
這裏BrandOrders與anyType的陣列。
我有一個類Product.java
public class Product {
String name;
String position;
int brandId;
boolean is_order;
boolean is_merchandising;
boolean is_audit;
Product(String product_name,String brand_position,int brandid,boolean isorder,boolean ismerchandising, boolean isaudit)
{
name = product_name;
position=brand_position;
brandId=brandid;
is_order = isorder;
is_merchandising = ismerchandising;
is_audit = isaudit;
}
}
我叫ViewYourPlanToday.java肯定的部分代碼API調用類看起來是這樣的:
SoapObject request = new SoapObject(RouteTrackerApp.NAMESPACE,
METHOD_NAME);
request.addProperty("Token", rep1);
request.addProperty("UserID",uid);
request.addProperty("StoreID", sid);
request.addProperty("BrandOrders",resultarray);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
RouteTrackerApp.URL);
try
{
androidHttpTransport.call(RouteTrackerApp.SOAP_ACTION, envelope);
SoapObject responseInner = (SoapObject) envelope.bodyIn;
System.out.println("class:"+envelope.bodyIn.getClass());
...... }
但我得到一個錯誤爲:
01-07 12:28:17.680: W/System.err(7867): java.lang.RuntimeException: Cannot serialize: [[email protected]]
01-07 12:28:17.710: W/System.err(7867): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:664)
01-07 12:28:17.710: W/System.err(7867): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:649)
01-07 12:28:17.730: W/System.err(7867): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:595)
01-07 12:28:17.730: W/System.err(7867): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:573)
01-07 12:28:17.730: W/System.err(7867): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:658)
01-07 12:28:17.740: W/System.err(7867): at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:555)
01-07 12:28:17.740: W/System.err(7867): at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:205)
01-07 12:28:17.770: W/System.err(7867): at org.ksoap2.transport.Transport.createRequestData(Transport.java:134)
01-07 12:28:17.770: W/System.err(7867): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:144)
01-07 12:28:17.780: W/System.err(7867): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
01-07 12:28:17.780: W/System.err(7867): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
任何人都可以幫我解決這個錯誤。
resultarray在我的節目由來自Product.java – arun
值如果resultarray是一個「產品」的對象,你需要讓烏爾類產品實現KVMserializable。檢查我的答案在這裏看到如何:http://stackoverflow.com/questions/9355707/how-to-create-soap-request-via-ksoap2/9369810#9369810 – shadesco