Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call webservice through ksoap2

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to call webservice through ksoap2, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Package com.study.ws; import java.io.IOException; import org.ksoap2.SoapEnvelope; import org.ksoap2.SoapFault; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; import org.ksoap2.transport.HttpTransportSE; import org.xmlpull.v1.XmlPullParserException; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener Import android.webkit.WebSettings; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class WSClient extends Activity {private Button search; private EditText phone; private TextView result; / * * Called when the activity is first created. * / @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.main); search= (Button) findViewById (R.id.search); phone= (EditText) findViewById (R.id.phone); result= (TextView) findViewById (R.id.result) Search.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {String strPhone=phone.getText (). ToString (). Trim (); if (! (strPhone.length () = = 0 | | strPhone.equals (")) {String str ="; try {str = getPhoneInfo (strPhone)) } catch (IOException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} catch (XmlPullParserException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} result.setText (str);}) } public String getPhoneInfo (String phoneName) throws IOException, the query result returned by XmlPullParserException {/ / String result = null; / / calls the namespace of the webservice API String nameSpace= "http://WebXml.com.cn/"; / / the method name called String methodName=" getMobileCodeInfo " / / bind method name and namespace together String SOAP_ACTION = nameSpace + methodName; / / get the request object SoapObject request = new SoapObject (nameSpace, methodName); / / set the parameter request.addProperty ("mobileCode", phoneName) that needs to be returned to the request object; request.addProperty ("userId", "") / / set the version of soap SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope.VER11); / / set whether to call the envelope.dotNet developed by dotNet = true; / / envelope.bodyOut = request; AndroidHttpTransport hts = new AndroidHttpTransport ("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"); / / web service request hts.call (SOAP_ACTION, envelope)) / / get the returned result Object o = envelope.getResponse (); result = o.toString (); return result;}} the above is how to call webservice through ksoap2. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report