For example, to query the Web service of a mobile phone number's attribution, its WSDL is
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
1 importing in Android projects ? ? ksoap2-android Jar Third party jar package ? ?
2 Activity Code
public class secondactivity extends activity {private edittext phonesecedittext; private textview resultview; private button querybutton; @ Override public void oncreate (Bundle savedinstancestate) { super.oncreate (savedInstanceState); setcontentview (R.layout.activity_second); phoneSecEditText = (EditText) Findviewbyid (r.id.phone_sec); resultview = (TextView) findviewbyid (r.id.result_text); queryButton = (Button) findviEwbyid (R.ID.QUERY_BTN); Querybutton.setonclicklistener (New onclicklistener () { @Override public void onclick (VIEW&NBSP;V) { // Mobile phone Number (segment) String Phonesec = phonesecedittext.gettext (). toString (). Trim (); // simple to determine whether the user entered the mobile phone number (segment) is legal if ("". Equals (phonesec) | | phonesec.length () &NBSP;<&NBSP;7) { // Give error hints phonesecedittext.seterror ( "You entered the mobile phone number (paragraph) is wrong!" "); phonesecedittext.requestfocus (); // empty the TextView that will display the results of the query resultview.settext (""); return; } // Enquiry Mobile Number (segment) Information // getremoteinfo ( PHONESEC); new mys (). Execute (PHONESEC) ; } }); } /** * Mobile phone number segment Attribution Enquiry * * @param phonesec Mobile phone number segment */ public string getremoteinfo (String phonesec) { // Namespaces String nameSpace = "http://WebXml.com.cn/"; // method Name of the call String methodName = "Getmobilecodeinfo"; // endpoint string endPoint = "Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"; // SOAP Action String soapAction = "Http://WebXml.com.cn/getMobileCodeInfo"; // Specify the namespace of the WebService and the method name of the call soapobject rpc = new soapobject (Namespace, methodname); // set the two parameters that need to be passed in to call the WebService interface Mobilecode, userid rpc.addproperty ("Mobilecode", phoneSec); rpc.addproperty ("UserId", ""); // generates SOAP request information that calls the WebService method and specifies the version of Soap SoapSerializationEnvelope envelope = new Soapserializationenvelope (SOAPENVELOPE.VER10); envelope.bodyout = rpc; // Set whether to invoke DotNet developed webservice envelope.dotnet = true; // equivalent to envelope.bodyout = rpc; envelope.setoutputsoapobject (RPC); httptransportse transport = new httptransportse ( EndPoint); try { // Call webservice transport.call (Soapaction, envelope); } catch (exception e) { e.printstacktrace (); } // Get the data returned SoapObject object = (Soapobject) envelope.bodyin; // gets the results returned string result = object.getproperty (0). toString (); // display the results returned by WebService in TextView // resultview.settext (Result); return result ; } class Mys extends AsyncTask<String, Void, string>{@Overrideprotected string doinbackground (string... params) {return Getremoteinfo (Params[0]) ;} @Overrideprotected void onpostexecute (String result) {resultview.settext (Result); super. OnPostExecute (result);} }}
which
namespace String nameSpace = "http://WebXml.com.cn/"; The method name called String methodName = "Getmobilecodeinfo"; EndPoint String EndPoint = "Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"; SOAP Action String soapaction = "Http://WebXml.com.cn/getMobileCodeInfo";
These values are
namespace, called method name, endpoint, and soap Action
EndPoint usually the remainder of the "? wsdl" at the end of the WSDL address is removed
The SOAP action is typically the name of the method called by the namespace +.
Reference: http://blog.csdn.net/lyq8479/article/details/6428288/
Android Call WebService interface