java - KSoap2 + Android + .net Ws = Null -
i'm having issues using ksoap2 in android project while conecting .net webservice. long call ws witouth parameters works fine, when try add parameters, servers never gets them. here's 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(); (int = 0; < count; i++) { object obj1 = node.getproperty(i); if (obj1 instanceof soapobject) { // don't recurse empty objects if (((soapobject)obj1).getpropertycount() > 0) { // recurse node process nodes/primitives getstringarrayresponse((soapobject)obj1, strings); } } else if (obj1 instanceof soapprimitive) { strings.add(((soapprimitive)obj1).tostring()); } } // make original caller if (isfirstcall) { return (string[])strings.toarray(new string[strings.size()]); } return null; } }
i harcode server side, return string + parameters send it.. , it's hardcoded part, seems parameters add soap objets never receives server.
allready try : -) removing "http://" namespace on webservice -) not using "envelope.dotnet = true;" -) adding property directly 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 use string ("riquelme") value integer?
what happens when run code? try setting envelope.debug = true
. trying setting breakpoint , inspecting value of envelope.requestdump
, envelope.responsedump
. way can see sent , received.
Comments
Post a Comment