web services - Accessing WebService from Android using ksoap2 -
after searching whole day still cannot find solution problem.
i have webservice, gives me following wsdl file, uploaded pastebin cause it's big.
for beginning i'd implement ping function, call string value , returns string value client. think relevant parts are:
<wsdl:operation name="ping"> <wsdl:input message="tns:ping" name="ping"></wsdl:input> <wsdl:output message="tns:pingresponse" name="pingresponse"></wsdl:output> <wsdl:fault message="tns:serverexception" name="serverexception"></wsdl:fault> <wsdl:fault message="tns:userexception" name="userexception"></wsdl:fault> </wsdl:operation>
and:
<xs:complextype name="ping"> <xs:sequence> <xs:element minoccurs="0" name="in" type="xs:string"/> </xs:sequence> </xs:complextype>
anyway nice if @ actual wsdl file , tell me if these relevant parts of it.
so, access android i'm using ksoap2. code looks followed:
soapobject request = new soapobject("http://shared.bimserver.org/", "ping"); request.addproperty("in", "hallo welt"); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.dotnet = true; envelope.setoutputsoapobject(request); httptransportse httptransport = new httptransportse("http://10.0.0.5:8082/soap"); httptransport.debug = true; httptransport.call("http://shared.bimserver.org/ping", envelope);
this creates following request:
<v:envelope xmlns:i="http://www.w3.org/2001/xmlschema-instance" xmlns:d="http://www.w3.org/2001/xmlschema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:header /><v:body><ping xmlns="http://shared.bimserver.org/" id="o0" c:root="1"><in i:type="d:string">hallo welt</in></ping></v:body></v:envelope>
but response:
<soap:body><soap:fault><faultcode>soap:client</faultcode><faultstring>unmarshalling error: unexpected element (uri:"http://shared.bimserver.org/", local:"in"). expected elements <{}in> </faultstring></soap:fault></soap:body>
so expect, parameter "in" mustn't have namespace. tried different things like:
propertyinfo info = new propertyinfo(); info.setname("in"); info.setnamespace(""); info.setvalue("hallo welt"); request.addproperty(info);
but didn't change request or response.
i removed namespace soap object:
soapobject request = new soapobject("", "ping");
which gives me following request:
<v:envelope xmlns:i="http://www.w3.org/2001/xmlschema-instance" xmlns:d="http://www.w3.org/2001/xmlschema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:header /><v:body><ping xmlns="" id="o0" c:root="1"><in i:type="d:string">hallo welt</in></ping></v:body></v:envelope>
and following response:
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:body><soap:fault><faultcode>soap:client</faultcode><faultstring>unexpected wrapper element ping found. expected {http://shared.bimserver.org/}ping.</faultstring></soap:fault></soap:body></soap:envelope>
so here seems, parameter "in" must not have namespace, ping request must have one.
please me. i've tried can imagine.
edit: soapui found out, response should that:
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:shar="http://shared.bimserver.org/"> <soapenv:header/> <soapenv:body> <shar:ping> <!--optional:--> <in>hallo</in> </shar:ping> </soapenv:body> </soapenv:envelope>
my request looks this:
<v:envelope xmlns:i="http://www.w3.org/2001/xmlschema-instance" xmlns:d="http://www.w3.org/2001/xmlschema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:header /> <v:body> <ping xmlns="http://shared.bimserver.org/"> <in i:type="d:string">test</in> </ping> </v:body> </v:envelope>
how request needed request?
here how make request .net web service , here calling function named "login" , can find name space service in soap envelop format shown in function link line here "http://www.example.com/" in namespace , function name id login. more details check this link
private static final string url = "http://www.example.com/service.asmx"; private static final string namespace = "http://www.example.com/"; final string soap_action = namespace+"login"; final string method_name ="login"; string response=null; soapobject request=new soapobject(namespace,method_name); request.addproperty("username",user_name); request.addproperty("password", password); soapserializationenvelope envelope=new soapserializationenvelope(soapenvelope.ver11); envelope.setaddadornments(false); envelope.implicittypes = true; envelope.dotnet=true; envelope.setoutputsoapobject(request); marshalbase64 marshal = new marshalbase64(); marshal.register(envelope); httptransportse httptransport = new httptransportse(url); httptransport.call(soap_action, envelope); soapprimitive soap_primitive = null; soap_primitive=(soapprimitive)envelope.getresponse(); response=string.valueof(soap_primitive);
Comments
Post a Comment