Android Personal Learning Note-use MyEclipse to quickly create webservice and invoke it in Android (cont.)

Source: Internet
Author: User

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.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.