KSoap2 + Android + .net Ws = Null

I am having problems using Ksoap2 in an android project when connecting to .net Webservice. While I call Ws witouth parameters, everything works fine, but when I try to add parameters, the servers will never get them. here is my code

import java.util.Vector;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ServicioWeb extends Activity {

SoapObject response;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   // String NAMESPACE = "http://tempuri.org/";
    String NAMESPACE = "IDBN.WS";
    String METHOD_NAME = "getClientesByName";
    //String SOAP_ACTION = "http://tempuri.org/getClientesByName";
    String SOAP_ACTION = "IDBN.WS/getClientesByName";
    //String URL = "http://www.ws.idbnar2.com.ar/wsClientes.asmx";
    String URL = "http://www.ws.idbnar2.com.ar/wsClientes.asmx";
    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
   PropertyInfo pi = new PropertyInfo();
    pi.setName("Nombre");
    pi.setValue("RIQUELME");
    pi.setType(int.class);
    Request.addProperty(pi);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(Request);
    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
    ListView Lista = (ListView)findViewById(R.id.Lista);

    try
    {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        response = (SoapObject)envelope.getResponse();
        String[] Clientes = getStringArrayResponse(response, null);
        Lista.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,Clientes));
    }
    catch(Exception e)
    {
        Toast toast = Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG);
        toast.show();
    }
}

public String[] getStringArrayResponse(SoapObject node, Vector<String> strings) {
    boolean isFirstCall = false;
    if (strings == null) {
        isFirstCall = true;
        strings = new Vector<String>();
    }
    int count = response.getPropertyCount();
    for (int i = 0; i < count; i++) {
        Object obj1 = node.getProperty(i);
        if (obj1 instanceof SoapObject) {
            // don't recurse empty objects
            if (((SoapObject)obj1).getPropertyCount() > 0) {
                // recurse into another node to process its nodes/primitives
                getStringArrayResponse((SoapObject)obj1, strings);
            }
        } else if (obj1 instanceof SoapPrimitive) {
            strings.add(((SoapPrimitive)obj1).toString());
        }
    }
    // only make this for the original caller
    if (isFirstCall) {
        return (String[])strings.toArray(new String[strings.size()]);
    }
    return null;
}
}

I pass the server side to return the string + parameters that I send them. Now I get this hard-coded part, it seems that the parameters that I add to soap objects are never received by the server.

All attempts: -) removing "http: //" from the namespace in Webservice -) without using "envelope.dotNet = true"; -) adding a property directly to the request

Any idea that is wrong ???

+3
source share
2

:

PropertyInfo pi = new PropertyInfo();
pi.setName("Nombre");
pi.setValue("RIQUELME");
pi.setType(int.class);
Request.addProperty(pi);

( "RIQUELME" ) ?

? envelope.debug = true. envelope.requestDump envelope.responseDump. , , .

+2
pi.setName("Nombre");
    pi.setValue("RIQUELME");
    pi.setType(int.class);
    Request.addProperty(pi);

pi.setValue (1, 2, ..) pi.setType string.class

pi.setType. , .

0

Source: https://habr.com/ru/post/1791097/


All Articles