2 Ответов

Рейтинг:
2

Suvendu Shekhar Giri

Пробовали искать это в гугл[^] прежде чем разместить этот вопрос здесь?

Проверьте эту статью
Звоню ASP.NET Webservice (ASMX) из приложения для Android, самый простой способ[^]

Следующая статья также может быть полезна-
Как позвонить asp.net веб - сервис в android[^]

Надеюсь, это поможет :)


Рейтинг:
0

ElieCh

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");
            //for linear parameter
            val request = SoapObject(NAMESPACE, METHOD_NAME)
            request.addProperty("SMS", "hi man"); // adding method property here serially
            request.addProperty("Sender", "444"); // adding method property here serially
            request.addProperty("MessageDateTime", "2010-05-24T18:13:00"); // adding method property here serially

            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) {
                // TODO Auto-generated catch block
                Log.e(TAG1, e.message)
                e.printStackTrace()
            } catch (e: IOException) {
                // TODO Auto-generated catch block
                Log.e(TAG2, e.message)
                e.printStackTrace()
            } catch (e: XmlPullParserException) {
                // TODO Auto-generated catch block
                Log.e(TAG3, e.message)
                e.printStackTrace()
            }
            //send request

            var result: Any? = null
            try {
                result = envelope.response as Any
                Log.i(TAG4, result.toString()) // see output in the console
            } catch (e: SoapFault) {
                // TODO Auto-generated catch block
                Log.e(TAG5, e.message)
                e.printStackTrace()
            }

            return null
        }
    }
}