1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
package com.example.root.myapplication; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.Toast; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; public class MainActivity extends AppCompatActivity { private static final String NAMESPACE = "http://tempuri.org/"; private static final String METHODNAME = "Add"; private static final String SOAPACTION = "http://tempuri.org/Add"; private static final String URL = "http://www.dneonline.com/calculator.asmx?wsdl"; String result = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.StartBT); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { TestService(); } }); } private void TestService() { AT at = new AT(); at.execute(); } private class AT extends AsyncTask<Void, Void, String>{ @Override protected void onPostExecute(String s) { super.onPostExecute(s); Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show(); } @Override protected String doInBackground(Void... params) { SoapObject soapObject = new SoapObject(NAMESPACE, METHODNAME); PropertyInfo intA = new PropertyInfo(); intA.setName("intA"); intA.setValue("25"); intA.setType(int.class); soapObject.addProperty(intA); PropertyInfo intB = new PropertyInfo(); intB.setName("intB"); intB.setValue("489"); intB.setType(int.class); soapObject.addProperty(intB); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(soapObject); HttpTransportSE httpTransportSE = new HttpTransportSE(URL); try { httpTransportSE.call(SOAPACTION, envelope); SoapPrimitive soapPrimitive = (SoapPrimitive) envelope.getResponse(); result = soapPrimitive.toString(); } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } //Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show(); return null; } } } |