Android personal learning notes-use myeclipse to quickly create webservice and call (CONTINUE) in Android. androidmyeclipse
2. Android 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/"; // call the method String methodName =" getInfoList "; // create the httpTransportSE transmission object HttpTransportSE ht = new HttpTransportSE (url); ht. debug = true; // use the soap1.1 protocol to create the Envelop object SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope. VER11); // instantiate SoapObject object SoapObject request = new SoapObject (nameSpace, methodName); // set parameters. The parameter name may not necessarily be the same as the parameter name on the called server, you only need to make the request in the same order. addProperty ("arg0", p_x + ""); request. addProperty ("arg1", p_y + ""); envelope. bodyOut = request; try {// web service request ht. call (null, envelope); // obtain the returned data result = envelope. getResponse (). toString ();} catch (Exception e) {// TODO: handle finished tione. printStackTrace (); result = "connection error";} return result ;}}
Ksoap is used for calling. It is the ksoap2-.. jar package and can be downloaded from Baidu.
In this way, you can obtain it in the activity. The function of this Android app is mainly to complete positioning, and the positioning longitude and latitude are used as parameters to call the web service. Then, a json string is returned, parse the string to obtain Information.