简体   繁体   English

KSoap2 + Android + .net Ws = Null

[英]KSoap2 + Android + .net Ws = Null

i'm having some issues using Ksoap2 in an android project while conecting to a .net Webservice. 我在一个Android项目中使用Ksoap2时会遇到一些问题,同时连接到.net Webservice。 As long as i call the Ws witouth parameters everything works just fine, but when i try to add parameters, the servers never gets them. 只要我调用Ws witouth参数一切正常,但是当我尝试添加参数时,服务器永远不会得到它们。 here's 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 harcode the server side, to return a string + the parameters i send it.. and now all i get it's the hardcoded part, seems like the parameters i add to the soap objets are never receives by the server. 我对服务器端进行了编码,返回一个字符串+我发送的参数..现在所有我得到的是硬编码部分,似乎我添加到soap objets的参数永远不会被服务器接收。

Allready try : -) removing the "http://" from the namespace on the Webservice -) not using the "envelope.dotNet = true;" Allready尝试: - )从Webservice上的命名空间中删除“http://” - )不使用“envelope.dotNet = true;” -) adding the Property directly into the Request - )将属性直接添加到请求中

Any idea wha'ts wrong??? 任何想法都错了???

These lines confuse me: 这些线条让我困惑:

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

Why do you use a string ("RIQUELME") as value for an integer? 为什么使用字符串(“RIQUELME”)作为整数的值?

What happens when you run the code? 运行代码会发生什么? Try setting envelope.debug = true . 尝试设置envelope.debug = true Trying setting a breakpoint and inspecting the value of envelope.requestDump and envelope.responseDump . 尝试设置断点并检查envelope.requestDumpenvelope.responseDump的值。 That way you can see what is sent and what is received. 这样你就可以看到发送的内容和收到的内容。

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

pi.setValue should either be an integer (1, 2, etc.) OR pi.setType should be string.class pi.setValue应该是一个整数(1,2等) 或者 pi.setType应该是string.class

Or, you don't need to have pi.setType . 或者,您不需要pi.setType If you delete that line, it should work. 如果删除该行,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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