ksoap2 - android soapfault error -



ksoap2 - android soapfault error -

i begginer in android,here have activity utilize web service:

soapobject request = new soapobject(namespace, method_name); getbounddata val = new getbounddata() { }; propertyinfo pi = new propertyinfo(); pi.setname("getbounddata"); pi.setvalue(val); pi.settype(getbounddata.class); request.addproperty(pi); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.setoutputsoapobject(request); marshal floatmarshal = new marshalfloat(); envelope.addmapping(namespace, getbounddata.class.getsimplename(), getbounddata.class); floatmarshal.register(envelope); httptransportse androidhttptransport = new httptransportse(url); androidhttptransport.debug =true; textview t = (textview)this.findviewbyid(r.id.resultbox); httptransportse androidhttptransport = new httptransportse(url); seek { androidhttptransport.call(soap_action, envelope); system.out.println("aht requestdump :"+androidhttptransport.requestdump); system.out.println("aht responsedump :"+androidhttptransport.responsedump); } grab (exception e) { e.printstacktrace(); } seek { object result = (object) envelope.bodyin; string s = result.tostring(); t.settext(s); } grab (classcastexception e) { // todo auto-generated grab block e.printstacktrace(); t.settext("1"); }

and in getbounddata class :

public abstract class getbounddata implements kvmserializable { string bound = "((-0.00021792948245596397, -0.0002648681402206421), (0.00021792948246868618, 0.0002648681402206421))"; string zoom ="21"; public object getproperty(int arg0) { switch (arg0){ case 0: homecoming bound; case 1: homecoming zoom; default: homecoming null; } } public int getpropertycount() { homecoming 2;//because have 2 parameters } public void getpropertyinfo(int arg0, hashtable arg1, propertyinfo arg2) { switch(arg0) { case 0: arg2.type = propertyinfo.string_class; arg2.name = "bound"; break; case 1: arg2.type = propertyinfo.string_class; arg2.name = "zoom"; break; default:break; } } public void setval(string bound, string zoom) { bound = bound; zoom = zoom; } public void setproperty(int arg0, object arg1) { switch(arg0) { case 0: bound = (string)arg1; break; case 1: zoom = (string)arg1; break; default: break; }

} }

and webservice xml

<wsdl:types> <s:schema elementformdefault="qualified" targetnamespace="http://tempuri.org/"> <s:element name="getbounddata"> <s:complextype> <s:sequence> <s:element minoccurs="0" maxoccurs="1" name="bound" type="s:string"/> <s:element minoccurs="0" maxoccurs="1" name="zoom" type="s:string"/> </s:sequence> </s:complextype> </s:element> <s:element name="getbounddataresponse"> <s:complextype> <s:sequence> <s:element minoccurs="0" maxoccurs="1" name="getbounddataresult" type="tns:arrayofanytype"/> </s:sequence> </s:complextype> </s:element> <s:complextype name="arrayofanytype"> <s:sequence> <s:element minoccurs="0" maxoccurs="unbounded" name="anytype" nillable="true"/> </s:sequence> </s:complextype> </s:schema> </wsdl:types>

here webservice sample:

request:

<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <getbounddata xmlns="http://tempuri.org/"> <bound>string</bound> <zoom>string</zoom> </getbounddata> </soap:body> </soap:envelope>

response:

<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <getbounddataresponse xmlns="http://tempuri.org/"> <getbounddataresult> <anytype /> <anytype /> </getbounddataresult> </getbounddataresponse> </soap:body> </soap:envelope>

but show :

soapfault - faultcode: 'soap:server' faultstring: 'server unable process request. ---> object reference not set instance of object.' faultactor: 'null' detail: org.kxml2.kdom.node@44efb360

i used soapobject getresponse() error occurred

thats because have complex type (ie objects) , adding "simple type" property. check reply here, explained in details needs done. have create local classes match complex type, these local classes should implement kvmserializable, example:

<s:element name="getbounddata"> <s:complextype> <s:sequence> <s:element minoccurs="0" maxoccurs="1" name="bound" type="s:string"/> <s:element minoccurs="0" maxoccurs="1" name="zoom" type="s:string"/> </s:sequence> </s:complextype>

means on web service, there exists class called "getbounddata". since using ksoap2 building manually soap envelope, have create such class in app , implementing kvmserializable ( ksoap2 serialization interface):

public class getbounddata implements kvmserializable { string bound; string zoom; @override public object getproperty(int arg0) { switch (arg0){ case 0: homecoming bound; case 1: homecoming zoom; default: homecoming null; } } @override public int getpropertycount() { homecoming 2;//because have 2 parameters } @override public void getpropertyinfo(int arg0, hashtable arg1, propertyinfo arg2) { switch(arg0) { case 0: arg2.type = propertyinfo.string_class; arg2.name = "bound"; break; case 1: arg2.type = propertyinfo.string_class; arg2.name = "zoom"; break; default:break; } } @override public void setproperty(int arg0, object arg1) { switch(arg0) { case 0: bound = (string)arg1; break; case 1: zoom = (string)arg1; break; default: break; } }

this how build locally match classes (object,ie complex type) on server). have add together necessary properties, build envelope, add together mapping , marshalling , send request. these steps explained in link mentioned above.

update i'll explain these are:

<wsdl:message name="getbounddatasoapin"> <wsdl:part name="parameters" element="tns:getbounddata"/> </wsdl:message>

when wsdl:message means function required on web service. has , means requires parameter of type getbounddata not primitive type, in fact complex type (object). here steps: 1- have write local representation , ie class, of complex type getbounddata ( wrote above) 2- in application have create (its u where) function phone call function related "getbounddatasoapin" on web service. idead create function name significat ie like:

public getbounddata getbounddata() { seek { soapobject sobj = new soapobject(your_namespace,the_method_name); //------------------------------------------------------------------------------ // getbounddata :adding property // <wsdl:message name="getbounddatasoapin"> // <wsdl:part name="parameters" element="tns:getbounddata"/> // </wsdl:message> // getbounddata has 2 params: // <s:element minoccurs="0" maxoccurs="1" name="bound" type="s:string"/> // <s:element minoccurs="0" maxoccurs="1" name="zoom" type="s:string"/> // //-------------------------------------------------------------------------- //-------------- // getbounddata //-------------- propertyinfo pi = new propertyinfo(); pi.setname("getbounddata"); pi.setvalue(whatever_value_your_supposed_to_put);// these values "bound" , "zoom" , they're supposed gotten in app somewhere pi.settype(getbounddata.class); sobj.addproperty(pi); //------------------------------ // start building soap envelope //------------------------------ soapserializationenvelope soapenvelope = new soapserializationenvelope(soapenvelope.ver11); soapenvelope.setoutputsoapobject(sobj); //--------------------------------------------------------------------------------------- // mappings: //--------------------------------------------------------------------------------------- soapenvelope.addmapping(your_namespace, getbounddata.class.getsimplename(), getbounddata.class); //--------------------------------------------------------------------------------------- // marshalling: //--------------------------------------------------------------------------------------- marshal floatmarshal = new marshalfloat(); floatmarshal.register(soapenvelope); androidhttptransport aht = new androidhttptransport(your_url); aht.debug = true; seek { aht.call(your_action, soapenvelope); //importat outputs check how request/response looks like.. check logcat find these outputs system.out.println("aht requestdump :"+aht.requestdump); system.out.println("aht responsedump :"+aht.responsedump); homecoming soapenvelope.getresponse(); } grab (exception e) { e.printstacktrace(); homecoming "exception: " + e.getmessage()+" message :" +e.getmessage()+" localizedmessage :"+e.getlocalizedmessage(); } } catch(exception ex) { ex.printstacktrace(); homecoming "exception: " + ex.getmessage(); } } }

so check logcat see shape of request , response, , you'll see if have response , parse utilize it, not sure response be, in case multidimensional array, had parse using java functionalities. for:

<wsdl:message name="getbounddatasoapout"> <wsdl:part name="parameters" element="tns:getbounddataresponse"/> </wsdl:message>

this tells web service sends response.

android ksoap2 soapfault

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -