简体   繁体   中英

web-service Ksoap2 Complex objects

I can´t solve this problem and go on... I have a big problem in my app. Any help would be really appreciated, I will try to put all the code.

Thank you very much!

The main error is this one:

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

The complex object that I want to send is this one:

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;
}

}

}

I send it by calling this method:

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;
    }

from this one: (is an AsyncTask)

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

        almacenaCoordenadas();
        return null;
    }

And the method in the webservice is this one:

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;
    }

The error is this one:

[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)

It looks like the webservice cant't process the object Coordenada..

Any help would be appreciated. Thank you very much!!

Unknow type {http://www.w3.org/2001/XMLSchema}Coordenada

This part seems to be the cause of the problem. You need to change the name value to what your server waits(that is not Coordenada as we see from the error).

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

addMapping(java.lang.String namespace, java.lang.String name,java.lang.Class clazz)
Defines a direct mapping from a namespace and name to a java class (and vice versa)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM