我有一个实现可序列化的自定义对象,在客户端项目和 web 服务项目中定义。我想通过soap消息将该对象作为字节数组传递,但是当我尝试这样做时,重建对象的web服务中的方法有一个找不到类的异常,如下面的堆栈:
java.lang.ClassNotFoundException: com.myproject.biosign.client.vo.Istante
请注意,异常中引用的路径是客户端中对象的路径,并且正确地在 web 服务中找不到。如何在 web 服务中使用相同对象的定义重建对象?
遵循转换、发送和反转换对象的代码。
在客户端方法中:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = null;
out = new ObjectOutputStream(bos);
out.writeObject(istanti.get(0));
byte[] yourBytes = bos.toByteArray();
out.close();
bos.close();
request.addProperty("lista", yourBytes);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
new MarshalBase64().register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
在 WS 方法中:
ByteArrayInputStream bis = new ByteArrayInputStream(lista);
ObjectInput in = null;
try {
in = new ObjectInputStream(bis);
Object o = in.readObject();
Istante ist = (Istante) o;
System.out.println("eccoci" + ist.getXCoord());
bis.close();
in.close();