Web服务Ksoap2复杂对象错误

时间:2013-11-14 00:55:55

标签: java android web-services ksoap2 android-ksoap2

我无法解决这个问题,继续...... 我的应用程序中存在很大问题。任何帮助将非常感激,我会尝试把所有的代码。

非常感谢!

主要错误是:

[ERROR] Exception occurred while trying to invoke service method almacenaCoordenadas
org.apache.axis2.AxisFault: Unknow type {http://www.w3.org/2001/XMLSchema}Coordenada

Coordenada类也在服务器中定义,服务器中的崩溃等待Coordenada对象

我要发送的复杂对象就是这个:

import java.util.Hashtable;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;



public class Coordenada implements KvmSerializable {


private long longitud;
private long latitud;

public Coordenada(long lat, long lon) {

    longitud = lon;
    latitud = lat;

}

public void setLongitud(long lon) {
    longitud = lon;
}

public void setLatitud(long lat) {
    latitud = lat;
}

public long getLongitud() {
    return longitud;
}

public long getLatitud() {
    return latitud;
}

@Override
public Object getProperty(int arg0) {

    switch (arg0) {
    case 0:
        return latitud;
    case 1:
        return longitud;

    }

    return null;
}

@Override
public int getPropertyCount() {

    return 2;
}



@Override
public void setProperty(int ind, Object val) {

    switch(ind){
    case 0:
        latitud = Long.parseLong(val.toString());
        break;
    case 1:
        longitud = Long.parseLong(val.toString());
        break;

    default:
        break;
    }

}

@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {

    switch(arg0){
    case 0:
        arg2.type = PropertyInfo.LONG_CLASS;
        arg2.name = "latitud";
        break;
    case 1:
        arg2.type = PropertyInfo.LONG_CLASS;
        arg2.name = "longitud";
        break;

    default:break;
}

}

}

我通过调用此方法发送它:

private String almacenaCoordenadas() {

        accionSoap = "http://ws.webapp.org/almacenaCoordenadas";
        metodo = "almacenaCoordenadas";
        String retorno="";

        try {

            // Modelo el request
            SoapObject request = new SoapObject(namespace, metodo);

            PropertyInfo primerParametro = new PropertyInfo();
            PropertyInfo segundoParametro = new PropertyInfo();
            //PropertyInfo tercerParametro = new PropertyInfo();
            primerParametro.setName("id");
            primerParametro.setValue(user);
            segundoParametro.setName("coord");
            segundoParametro.setValue(coordenada);
            request.addProperty(primerParametro);
            request.addProperty(segundoParametro);

            /*
            segundoParametro.setName("lo");
            segundoParametro.setValue(longitud);
            tercerParametro.setName("lat");
            tercerParametro.setValue(latitud);
            request.addProperty(primerParametro);
            request.addProperty(segundoParametro);
            request.addProperty(tercerParametro);*/


            // Modelo el Sobre
            SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            // si esta hecho o no en puntoNet
            sobre.dotNet = false;
            sobre.setOutputSoapObject(request);

                    sobre.AddMapping(namespace, "Coordenada", new Coordenada().getClass();

            // Modelo el transporte
            HttpTransportSE transporte = new HttpTransportSE(url);

            // Llamada
            System.out.println(sobre);
            transporte.call(accionSoap, sobre);

            // Resultado
            SoapPrimitive resultado = (SoapPrimitive) sobre.getResponse();

            retorno = resultado.toString();

            if (retorno!=null)
                Log.i("Resultado", "Envio correcto de coordenada");

        } catch (Exception e) {
            String s="";
            s+="ERROR - Envio de coordenada\n";
            s+=e.toString();
            Log.e("MainActivity",s);

        }

        return retorno;
    }

从这一个:(是一个AsyncTask)

@Override
    protected String doInBackground(String... params) {

        almacenaCoordenadas();
        return null;
    }

Web服务中的方法是这样的:

public String almacenaCoordenadas(String id, Coordenada coord){
        String resultado="Coordenadas recibidas correctamente";

        System.out.println(id+" esta en las coordenadas:");
        if(coord!=null){
            System.out.println("Llega coordenada");
        }

        return resultado;
    }

错误就是这个:

[ERROR] Exception occurred while trying to invoke service method almacenaCoordenadas
org.apache.axis2.AxisFault: Unknow type {http://www.w3.org/2001/XMLSchema}Coordenada
    at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:340)
    at org.apache.axis2.databinding.utils.BeanUtil.processObject(BeanUtil.java:818)
    at org.apache.axis2.databinding.utils.BeanUtil.ProcessElement(BeanUtil.java:737)
    at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:646)
    at org.apache.axis2.rpc.receivers.RPCUtil.processRequest(RPCUtil.java:153)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:206)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

看起来网络服务无法处理对象Coordenada ..

任何帮助将不胜感激。 非常感谢!!

1 个答案:

答案 0 :(得分:0)

通过添加以下内容启用调试:

transporte.debug = true;//ADD THIS

transporte.call(accionSoap, sobre);

System.out.println("requestDump is :"+transporte.requestDump);//ADD THIS
System.out.println("responseDump is :"+transporte.responseDump);//ADD THIS

然后在上面发布你的请求和responseDump,看看你的肥皂信封是什么样的。