<span id="Label3"></p><p><p>Download ksoap2.jar,</p></p><p><p></p></p><pre><pre>Import org.ksoap2.SoapEnvelope;<br>Import org.ksoap2.serialization.*;<br>Import org.ksoap2.transport.HttpTransportSE;<br>Import android.os.Handler;<br><br></pre></pre><pre><pre>Handler Handler = new Handler () {<br><br> @Override<br> public void Handlemessage (Message Msg) {<br> Super.handlemessage (msg);<br> Bundle bundle= Msg.getdata ();<br> String result=bundle.getstring ("result");<br><br> Toast.maketext (loginactivity.this,result,toast.length_short). Show ();<br> }<br>};<br><br></pre></pre><pre>New Thread () {<br>public void Run () {<br><br>String Namespace = "http://tempuri.org/";<br>String MethodName = "userlogin";<br>String Web_service_url = "http://192.168.4.2/myWeb/User.asmx";<br><br>Soapobject request = new Soapobject (Namespace, MethodName);<br>2, set the parameter value of the calling method, if there are no parameters, can be omitted,<br><br><br>3. Generate SOAP request information that calls the WebService Method. This information is described by the Soapserializationenvelope object<br>Soapserializationenvelope envelope = new Soapserializationenvelope (<br>soapenvelope.ver12);<br>Envelope.bodyout = request;<br>C # Write the application must add this sentence<br>Envelope.dotnet = true;<br>Httptransportse ht = new Httptransportse (web_service_url);<br>To invoke the WebService method by using the Call method<br>try {<br><br>Ht.call (null, envelope);<br>} catch (Exception E) {<br>E.printstacktrace ();<br>}<br>try {<br>Final soapprimitive result = (soapprimitive) Envelope.getresponse ();<br>If (result! = Null) {<br>LOG.D ("----received reply----", result.tostring ());<br><br><br>Message Message=new message ();<br>Bundle Bundle=new Bundle ();<br>Bundle.putstring ("result", result.tostring ());<br>Message.setdata (bundle);<br>Handler.sendmessage (message);<br><br><br>}<br><br><br>} catch (Exception E) {<br>LOG.E ("----error---", e.getmessage ());<br>E.printstacktrace ();<br>}<br>}<br>}.start ();</pre><p><p>Android Calls. NET WebServices</p></p></span>
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