class MainActivity : AppCompatActivity() {
private val MainURL ="http://192.168.1.125/SendMessageService.asmx"
private val SOAP_ACTION = "http://tempuri.org/InsertMessage"
private val METHOD_NAME = "InsertMessage"
private val NAMESPACE = "http://tempuri.org/"
private val TAG = "TRAINING"
private val TAG1 = "TRAINING1"
private val TAG2 = "TRAINING2"
private val TAG3 = "TRAINING3"
private val TAG4 = "TRAINING4"
private val TAG5 = "TRAINING5"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn01.setOnClickListener{
val myRequest = myAsyncTask()
myRequest.execute()
}
}
private inner class myAsyncTask : AsyncTask<Void, Void, Void>() {
override fun doInBackground(vararg params: Void): Void? {
val URL = MainURL
System.setProperty("http.keepAlive", "false");
val request = SoapObject(NAMESPACE, METHOD_NAME)
request.addProperty("SMS", "hi man");
request.addProperty("Sender", "444");
request.addProperty("MessageDateTime", "2010-05-24T18:13:00");
val envelope = SoapSerializationEnvelope(SoapEnvelope.VER11)
envelope.implicitTypes = true
envelope.setOutputSoapObject(request)
envelope.dotNet = true
val httpTransport = HttpTransportSE(URL)
httpTransport.debug = true
try {
httpTransport.call(SOAP_ACTION, envelope)
} catch (e: HttpResponseException) {
Log.e(TAG1, e.message)
e.printStackTrace()
} catch (e: IOException) {
Log.e(TAG2, e.message)
e.printStackTrace()
} catch (e: XmlPullParserException) {
Log.e(TAG3, e.message)
e.printStackTrace()
}
var result: Any? = null
try {
result = envelope.response as Any
Log.i(TAG4, result.toString())
} catch (e: SoapFault) {
Log.e(TAG5, e.message)
e.printStackTrace()
}
return null
}
}
}