Android Call WebService interface

Source: Internet
Author: User
Tags dotnet wsdl

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;&LT;&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

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.