Android background service ksoap error -
i developing android application background service consumes method of web service on every 5 mins. using ksoap 2.4 , asp.net web service. android background service running on every 5 mins but
androidhttptransport.call(soap_action+webmethname, envelope);
returns null. here android service code.
package com.example.rashid.challandb; import android.app.service; import android.content.context; import android.content.intent; import android.os.ibinder; import org.ksoap2.soapenvelope; import org.ksoap2.serialization.marshalbase64; import org.ksoap2.serialization.propertyinfo; import org.ksoap2.serialization.soapobject; import org.ksoap2.serialization.soapserializationenvelope; import org.ksoap2.transport.httptransportse; public class testservice extends service { private static string namespace = "http://tempuri.org/"; private static string url = "http://192.168.50.107:80/androidservice/service1.asmx"; private static string soap_action = "http://tempuri.org/"; context context; boolean isrunning; public testservice() { } @override public void oncreate() { this.context=this; this.isrunning=false; } @override public ibinder onbind(intent intent) { return null; } @override public int onstartcommand(intent intent,int flags,int startid) { if (!this.isrunning) { this.isrunning = true; synchronized (this) { try { string restxt = "default"; string webmethname="mymethod"; soapobject request = new soapobject(namespace, webmethname); propertyinfo first = new propertyinfo(); first.setname("para"); first.setvalue("hullow"); first.settype(string.class); request.addproperty(first); soapserializationenvelope envelope = new soapserializationenvelope( soapenvelope.ver11); envelope.dotnet = true; envelope.setoutputsoapobject(request); httptransportse androidhttptransport = new httptransportse(url); try { androidhttptransport.call(soap_action+webmethname, envelope); object response = null; response = (object) envelope.getresponse(); restxt =response.tostring(); } catch (exception e) { e.printstacktrace(); system.out.println( e.getmessage()+" phone"); } system.out.println( restxt); } catch (exception ex) { system.out.println("error:" + ex.getmessage()); } this.isrunning = false; stopself(); } } return start_sticky; } @override public void ondestroy() { this.isrunning=false; } }
here wsdl
<wsdl:definitions xmlns:s="http://www.w3.org/2001/xmlschema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textmatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetnamespace="http://tempuri.org/"> <wsdl:types> <s:schema elementformdefault="qualified" targetnamespace="http://tempuri.org/"> <s:element name="mymethod"> <s:complextype> <s:sequence> <s:element minoccurs="0" maxoccurs="1" name="para" type="s:string"/> </s:sequence> </s:complextype> </s:element> <s:element name="mymethodresponse"> <s:complextype> <s:sequence> <s:element minoccurs="0" maxoccurs="1" name="mymethodresult" type="s:string"/> </s:sequence> </s:complextype> </s:element> </s:schema> </wsdl:types> <wsdl:message name="mymethodsoapin"> <wsdl:part name="parameters" element="tns:mymethod"/> </wsdl:message> <wsdl:message name="mymethodsoapout"> <wsdl:part name="parameters" element="tns:mymethodresponse"/> </wsdl:message> <wsdl:porttype name="service1soap"> <wsdl:operation name="mymethod"> <wsdl:input message="tns:mymethodsoapin"/> <wsdl:output message="tns:mymethodsoapout"/> </wsdl:operation> </wsdl:porttype> <wsdl:binding name="service1soap" type="tns:service1soap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="mymethod"> <soap:operation soapaction="http://tempuri.org/mymethod" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="service1soap12" type="tns:service1soap"> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="mymethod"> <soap12:operation soapaction="http://tempuri.org/mymethod" style="document"/> <wsdl:input> <soap12:body use="literal"/> </wsdl:input> <wsdl:output> <soap12:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="service1"> <wsdl:port name="service1soap" binding="tns:service1soap"> <soap:address location="http://192.168.50.107/androidservice/service1.asmx"/> </wsdl:port> <wsdl:port name="service1soap12" binding="tns:service1soap12"> <soap12:address location="http://192.168.50.107/androidservice/service1.asmx"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
try replace
androidhttptransport.call(soap_action+webmethname, envelope);
with this
androidhttptransport.call("", envelope);
even not solved, please check exception return in line
system.out.println("error:" + ex.getmessage());
edit
soapobject request = new soapobject(namespace, webmethname); request.addproperty("para", "hullow");
remove propertyinfo part
Comments
Post a Comment