1

I have a problem while calling the webservice, I have a .NET web service in the server and I am using KSOAP(ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar) in Android. While running the program I got an runtime Exception named "org.ksoap2.serialization.SoapPrimitive".

I tried with the options that i readed in the link: How to call a .NET Webservice from Android using KSOAP2? and kSoap2 Android -- Cast Class Exception (SoapObject) but nothing help me

This my code:

try{
            //Conexión a Web Service
            SoapObject Solicitud = new SoapObject(NAMESPACE, METODO);

            PropertyInfo sector = new PropertyInfo();
            sector.setName("sector");
            sector.setValue(sectorX.toString());
            Solicitud.addProperty(sector);

            SoapSerializationEnvelope Envoltorio = new SoapSerializationEnvelope (SoapEnvelope.VER12);
            Envoltorio.dotNet = true;

            Envoltorio.setOutputSoapObject (Solicitud);

            HttpTransportSE TransporteHttp = new HttpTransportSE(URL);
            TransporteHttp.call (SOAP_ACTION, Envoltorio);

          //Obtencion de datos
            SoapObject resultado = (SoapObject)Envoltorio.getResponse();

            final String[] testValues = new String[resultado.getPropertyCount()];
            final Number[] serie = new Number[resultado.getPropertyCount()];

            for(int i= 0; i< resultado.getPropertyCount(); i++){
                String x = ""; 
                SoapObject wii = (SoapObject)resultado.getProperty(i);
                x += wii.getPropertyAsString(1);                
                testValues[i] = wii.getPropertyAsString(1);
                x.trim();
                serie[i]=Integer.parseInt(x);
            }

        ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this, R.layout.lista_sectores, testValues);
        final ListView LstOpciones = (ListView) findViewById(R.id.LstOpciones);
        LstOpciones.setAdapter(adaptador);

        LstOpciones.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View itemClicked,
                    int position, long id) {
                // TODO Auto-generated method stub
                TextView textview = (TextView)itemClicked;
                String strText = textview.getText().toString(); 
                seleccion.setText("Seleccionado: " + strText);

            } catch (Exception e){
        txtMensaje.setText(e.getMessage());
            }

Where sectorX it's a String parameter that I give to WS.

I tried the Web service without parameters and works! The problem is when I send parameter... I guess :/

Community
  • 1
  • 1
fmgh
  • 168
  • 4
  • 14

2 Answers2

1

There is no exception of that name. You probably get a class cast exception. If you debug you will probably find that your response is a SoapObject. So then you use getProperty or getAttribute or whatever on it. IF you set a break point you will be able to browse the object graph and assemble your parse code manually ..

Maybe post the stacktrace somewhere..

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • 1
    Yeah, that it's not the name of exception but it's appear in the TextView :) And I check that... if i use SoapObject the text have: "org.ksoap2.serialization.SoapPrimitive" and if i use SoapPrimitive said: "org.ksoap2.serialization.SoapObject". – fmgh Jul 25 '11 at 18:24
  • So, i dont know what happend but this occurs when I use paremeters. I can call web services without parameters and such. – fmgh Jul 25 '11 at 18:37
  • Like I said.. see what you get as a response by debugging as documented on the wiki and parse it accordingly. – Manfred Moser Jul 25 '11 at 20:19
  • Well, I'm a noob in this so... in the Debug appears: e.ClassCastException (id=830008144824) = java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive Cause = ClassCastException (id=830008144824) = java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive Detail message = "org.ksoap2.serialization.SoapPrimitive" stackState = Exception processing async thread queue Exception processing async thread queue org.eclipse.jdt.internal.debug.core.model.JDIObjectValue cannot be cast to org.eclipse.jdt.debug.core.IJavaArray stackTrace = null HELP :( – fmgh Jul 25 '11 at 21:47
  • so what object is returned from getResponse.. probably a SoapObject.. so where does the SoapPrimitive cast appear .. debug and fix there.. – Manfred Moser Jul 27 '11 at 02:47
  • But where do I that? Before or after of SoapObject resultado = (SoapObject)Envoltorio.getResponse(); ??? I did not cast anything (I guess), only I call to web service. In fact, this its a second activity of the project, in the first activity I write the same code and not problem :S – fmgh Jul 28 '11 at 17:11
  • Just do a Object response = Envoltorio.getResponse() .. the (SoapObject) is the cast that breaks it.. if you set a debug point in that line you will see – Manfred Moser Jul 29 '11 at 16:31
  • I wasn't solve my problem because i delete accidentally my code xD So, i check in this post as resolved. I hope that this ask help somebody in the future ^^u – fmgh Aug 21 '11 at 21:34
  • Next time use a version control system like git ;-) – Manfred Moser Aug 23 '11 at 04:32
0

You can try using only 'Object' instead of using 'SoapObject'. It works for me. Hope it helps.