java - Getting Exception While Invoking Web Service From Android -
i beginner in this, facing issue while invoking asp.net web service method (signup) android. works fine when try browser when android gives me exception "
soapfault - faultcode: 'soap:client' faultstring: 'system.web.services.protocols.soapexception: server did not recognize value of http header soapaction: signup. @ system.web.services.protocols.soap11serverprotocolhelper.routerequest() @ system.web.services.protocols.soapserverprotocol.initialize() @ system.web.services.protocols.serverprotocol.setcontext(type type, httpcontext context, httprequest request, httpresponse response) @ system.web.services.protocols.serverprotocolfactory.create(type type, httpcontext context, httprequest request, httpresponse response, boolean& abortprocessing)' faultactor: 'null' detail: org.kxml2.kdom."
this java signup class
string soap_action1 = "http://tempuri.org/signup"; string method_name1 = "signup"; btn = (button)findviewbyid(r.id.btn_signup); btn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { new webservice().execute(method_name1,soap_action1,txt_name.gettext().tostring(), txt_email.gettext().tostring(),txt_password.gettext().tostring(), txt_address.gettext().tostring(), txt_dob.gettext().tostring(), txt_account.gettext().tostring(), txt_cnic.gettext().tostring(),txt_pobox.gettext().tostring(), txt_city.gettext().tostring(),txt_status.gettext().tostring());
this java webservice class
private static string namespace = "http://tempuri.org/"; private static string url = "http://192.168.0.102/mywebservice/webservice1.asmx?wsdl"; protected string doinbackground(string... params) { string s=""; string whichmethodcall = params[0]; switch(whichmethodcall){ case "signup": s = signup(params); break; case "signin": s = signin(params); break; } return s; } public string signup(string[] arr){ string s = ""; soapobject request = new soapobject(namespace, arr[1]); //use add parameters request.addproperty("cname",arr[2]); request.addproperty("cemail",arr[3]); request.addproperty("cpwd",arr[4]); request.addproperty("caddress",arr[5]); request.addproperty("cdob",arr[6]); request.addproperty("caccount",arr[7]); request.addproperty("ccnic",arr[8]); request.addproperty("cpobox",arr[9]); request.addproperty("ccity",arr[10]); request.addproperty("cstatus",arr[11]); //declare version of soap request soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.setoutputsoapobject(request); envelope.dotnet = true; try { httptransportse androidhttptransport = new httptransportse(url); //this actual part call webservice androidhttptransport.call(arr[0], envelope); // soapresult envelope body. // soapobject result = (soapobject)envelope.bodyin; // soapobject result = (soapobject) envelope.getresponse(); if (envelope.bodyin instanceof soapfault) { final soapfault result = (soapfault) envelope.bodyin; if (result != null) { //get first property , change label text s = result.tostring(); } else s = "no response"; } } catch (exception e) { e.printstacktrace(); s=e.getmessage().tostring(); } return s; }
and asp.net webservice method
public string signup(string cname, string caddress, string cdob, long caccount, long ccnic, int cpobox, string ccity, string cstatus,string cemail, string cpass) { bool check = connectdb(); // opens connection insert new user string msg = ""; //datetime dob = datetime.parseexact(cdob, "dd/mm/yyyy", null); string query = "insert customers values('" + cname + "','" + caddress + "','" + cdob + "','" + caccount + "','" + ccnic + "','" + cpobox + "','" + ccity + "','" + cstatus + "','"+ cemail + "','"+ cpass + "')"; sqlcommand comm = new sqlcommand(query, con); try{ if (check == true){ if (comm.executenonquery() > 0) msg = "you've signed !"; else msg = "sign error"; } else msg = "database not connected"; }catch (sqlexception ex){ msg = ex.message.tostring(); con.close(); }finally{ con.close(); } return msg; }
can try this
instead of soapobject request = new soapobject(namespace, arr[1]); use
soapobject request = new soapobject(namespace, arr[0]);
in soap object should pass method name, without http://...
Comments
Post a Comment