2, the Android terminal WebService call
Package Net.zmqc.service;import Org.ksoap2.soapenvelope;import Org.ksoap2.serialization.soapobject;import Org.ksoap2.serialization.soapserializationenvelope;import Org.ksoap2.transport.httptransportse;public Class Infowebservice {public static String Soapcallwebservice (double p_x,double p_y) {string result = "No data appears!!!!!!!! "; String url = "Http://127.0.0.1:8080/InfoGpsService/InfoServicePort"; String nameSpace = "http://service.zmqc.net/";//method to invoke String methodName = "Getinfolist"; Create Httptransportse Transport Object Httptransportse HT = new Httptransportse (URL); Ht.debug = true; Create envelop objects using the soap1.1 protocol soapserializationenvelope envelope = new Soapserializationenvelope (SOAPENVELOPE.VER11); Instantiate the Soapobject object Soapobject request = new Soapobject (NameSpace, methodName); parameters, parameter names do not need to be the same as the call server-side parameter names, only the corresponding order of the same can be Request.addproperty ("arg0", p_x+ ""); Request.addproperty ("Arg1", p_y+ ""); Envelope.bodyout = Request;trY {//Web service request Ht.call (null, envelope);//Gets the returned data result = Envelope.getresponse (). toString ();} catch (Exception e) {// Todo:handle exceptione.printstacktrace (); result = "Connection error";} return result;}}
Call adopted is Ksoap, is KSOAP2-... jar package, can Baidu download
This can be obtained in the activity, the Android app's function is to complete the positioning, and the location of latitude and longitude as a parameter to call the Web service, and then return a JSON string, through the parsing of the string, get information
Android Personal Learning Note-use MyEclipse to quickly create webservice and invoke it in Android (cont.)