我想访问wcf webservice,如下面的代码:
void farmCreate(String userName,
String authToken) {
String resultData = null;
Hashtable<String, String> responseHashTable = new Hashtable<String, String>();
try {
FarmClass farm = new FarmClass();
StringBuilder sb = null;
SoapObject request = new SoapObject(Controller.NAMESPACE, "MethodName");
request.addProperty("aaaa", userName);
request.addProperty("aaaa", authToken);
request.addProperty("aaaa", farm);
request.addProperty("aaaaa", "Add");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
MarshalDate md = new MarshalDate();
md.register(envelope);
MarshalFloat md1 = new MarshalFloat();
md1.register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(Controller.URL6767);
androidHttpTransport.call(Controller.SOAP_ACTION + "method name", envelope);
//new MarshalBase64().register(envelope);
Object result = (Object) envelope.getResponse();
resultData = result.toString();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("error is occured :-" + e.getMessage());
}
}
但作为回应,产生如下错误: -
06-20 12:50:03.673: W/System.err(596): java.lang.RuntimeException: Cannot serialize: []
06-20 12:50:03.673: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:679)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:663)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:632)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:675)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:663)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:632)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:616)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:673)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:597)
06-20 12:50:03.684: W/System.err(596): at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:192)
06-20 12:50:03.694: W/System.err(596): at org.ksoap2.transport.Transport.createRequestData(Transport.java:101)
06-20 12:50:03.694: W/System.err(596): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
06-20 12:50:03.694: W/System.err(596): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
06-20 12:50:03.694: W/System.err(596): at com.track.controller.SoapWebService.farmCreate(SoapWebService.java:113)
06-20 12:50:03.694: W/System.err(596): at com.track.view.LiveStock.onCreate(LiveStock.java:82)
06-20 12:50:03.694: W/System.err(596): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-20 12:50:03.694: W/System.err(596): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-20 12:50:03.704: W/System.err(596): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
06-20 12:50:03.704: W/System.err(596): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
06-20 12:50:03.704: W/System.err(596): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
所以请,任何人都有关于序列化概念的想法所以请让我。 提前谢谢。
答案 0 :(得分:0)
要序列化任何对象,您应该实现Serializable。尝试为FarmClass实现Serializable类。