结果为空。Can';使用Ksoap2-android(使用Kotlin)无法从SOAP api获得响应

结果为空。Can';使用Ksoap2-android(使用Kotlin)无法从SOAP api获得响应,kotlin,ksoap2,android-ksoap2,Kotlin,Ksoap2,Android Ksoap2,我正在尝试使用android-Ksoap2库从SOAP API获取响应。但结果却出乎我的意料。API运行良好。我与POSTMAN一起使用POST请求和XML进行了测试 我对XML文件的请求是。。(名称空间屏蔽) 我实际上解决了这个问题。为了将来的参考,我写下我是如何解决的 这是我的问题的一部分 envelope.dotNet = true 完整方法 fun getRealTimeStopData(stopId : String?, forceRefresh: String?) : Mutab

我正在尝试使用android-Ksoap2库从SOAP API获取响应。但结果却出乎我的意料。API运行良好。我与POSTMAN一起使用POST请求和XML进行了测试

我对XML文件的请求是。。(名称空间屏蔽)


我实际上解决了这个问题。为了将来的参考,我写下我是如何解决的

这是我的问题的一部分

envelope.dotNet = true 
完整方法

fun getRealTimeStopData(stopId : String?, forceRefresh: String?) : MutableList<Bus> {

        var busList: MutableList<Bus> = mutableListOf()
        val METHOD_NAME = "GetRealTimeStopData"
        val SOAP_ACTION = Utils.SOAP_NAMESPACE + METHOD_NAME
        val soapObject = SoapObject(Utils.SOAP_NAMESPACE, METHOD_NAME)

        soapObject.addProperty("stopId", stopId)
        soapObject.addProperty("forceRefresh", forceRefresh)

        val envelope = SoapSerializationEnvelope(SoapEnvelope.VER11)
        envelope.setOutputSoapObject(soapObject)

        envelope.dotNet = true // This should be TRUE *important 

        val httpTransportSE = HttpTransportSE(Utils.SOAP_URL)

        try {
            httpTransportSE.call(SOAP_ACTION, envelope)
            val soapPrimitive: SoapObject = envelope.response as SoapObject

            // index 1 is Stopdata.
            var data: SoapObject = soapPrimitive.getProperty(1) as SoapObject
            // get to "Document Element"
            if(data.hasProperty("DocumentElement")){
                var documentElement: SoapObject = data.getProperty("DocumentElement") as SoapObject

                for(i in 1..documentElement.propertyCount) {
                    var obj = documentElement.getProperty(i-1) as SoapObject

                    var bus = Bus()
                    bus.MonitoredStopVisit_MonitoringRef = obj.getProperty("MonitoredStopVisit_MonitoringRef").toString()
                    bus.MonitoredVehicleJourney_LineRef = obj.getProperty("MonitoredVehicleJourney_LineRef").toString()
                    bus.MonitoredVehicleJourney_DirectionRef = obj.getProperty("MonitoredVehicleJourney_DirectionRef").toString()
                    bus.MonitoredVehicleJourney_PublishedLineName = obj.getProperty("MonitoredVehicleJourney_PublishedLineName").toString()
                    bus.MonitoredVehicleJourney_DestinationRef = obj.getProperty("MonitoredVehicleJourney_DirectionRef").toString()
                    bus.MonitoredVehicleJourney_DestinationName = obj.getProperty("MonitoredVehicleJourney_DestinationName").toString()
                    bus.MonitoredCall_ExpectedArrivalTime = obj.getProperty("MonitoredCall_ExpectedArrivalTime").toString()
                    bus.MonitoredCall_ExpectedDepartureTime = obj.getProperty("MonitoredCall_ExpectedDepartureTime").toString()

                    busList.add(bus)
                }
            } else {
                Log.v("**DEBUG**","busList size : " + busList.size.toString())
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

        return busList
    }

我实际上解决了这个问题。为了将来的参考,我写下我是如何解决的

这是我的问题的一部分

envelope.dotNet = true 
完整方法

fun getRealTimeStopData(stopId : String?, forceRefresh: String?) : MutableList<Bus> {

        var busList: MutableList<Bus> = mutableListOf()
        val METHOD_NAME = "GetRealTimeStopData"
        val SOAP_ACTION = Utils.SOAP_NAMESPACE + METHOD_NAME
        val soapObject = SoapObject(Utils.SOAP_NAMESPACE, METHOD_NAME)

        soapObject.addProperty("stopId", stopId)
        soapObject.addProperty("forceRefresh", forceRefresh)

        val envelope = SoapSerializationEnvelope(SoapEnvelope.VER11)
        envelope.setOutputSoapObject(soapObject)

        envelope.dotNet = true // This should be TRUE *important 

        val httpTransportSE = HttpTransportSE(Utils.SOAP_URL)

        try {
            httpTransportSE.call(SOAP_ACTION, envelope)
            val soapPrimitive: SoapObject = envelope.response as SoapObject

            // index 1 is Stopdata.
            var data: SoapObject = soapPrimitive.getProperty(1) as SoapObject
            // get to "Document Element"
            if(data.hasProperty("DocumentElement")){
                var documentElement: SoapObject = data.getProperty("DocumentElement") as SoapObject

                for(i in 1..documentElement.propertyCount) {
                    var obj = documentElement.getProperty(i-1) as SoapObject

                    var bus = Bus()
                    bus.MonitoredStopVisit_MonitoringRef = obj.getProperty("MonitoredStopVisit_MonitoringRef").toString()
                    bus.MonitoredVehicleJourney_LineRef = obj.getProperty("MonitoredVehicleJourney_LineRef").toString()
                    bus.MonitoredVehicleJourney_DirectionRef = obj.getProperty("MonitoredVehicleJourney_DirectionRef").toString()
                    bus.MonitoredVehicleJourney_PublishedLineName = obj.getProperty("MonitoredVehicleJourney_PublishedLineName").toString()
                    bus.MonitoredVehicleJourney_DestinationRef = obj.getProperty("MonitoredVehicleJourney_DirectionRef").toString()
                    bus.MonitoredVehicleJourney_DestinationName = obj.getProperty("MonitoredVehicleJourney_DestinationName").toString()
                    bus.MonitoredCall_ExpectedArrivalTime = obj.getProperty("MonitoredCall_ExpectedArrivalTime").toString()
                    bus.MonitoredCall_ExpectedDepartureTime = obj.getProperty("MonitoredCall_ExpectedDepartureTime").toString()

                    busList.add(bus)
                }
            } else {
                Log.v("**DEBUG**","busList size : " + busList.size.toString())
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

        return busList
    }
fun getRealTimeStopData(stopId : String?, forceRefresh: String?) : MutableList<Bus> {

        var busList: MutableList<Bus> = mutableListOf()
        val METHOD_NAME = "GetRealTimeStopData"
        val SOAP_ACTION = Utils.SOAP_NAMESPACE + METHOD_NAME
        val soapObject = SoapObject(Utils.SOAP_NAMESPACE, METHOD_NAME)

        soapObject.addProperty("stopId", stopId)
        soapObject.addProperty("forceRefresh", forceRefresh)

        val envelope = SoapSerializationEnvelope(SoapEnvelope.VER11)
        envelope.setOutputSoapObject(soapObject)

        envelope.dotNet = true // This should be TRUE *important 

        val httpTransportSE = HttpTransportSE(Utils.SOAP_URL)

        try {
            httpTransportSE.call(SOAP_ACTION, envelope)
            val soapPrimitive: SoapObject = envelope.response as SoapObject

            // index 1 is Stopdata.
            var data: SoapObject = soapPrimitive.getProperty(1) as SoapObject
            // get to "Document Element"
            if(data.hasProperty("DocumentElement")){
                var documentElement: SoapObject = data.getProperty("DocumentElement") as SoapObject

                for(i in 1..documentElement.propertyCount) {
                    var obj = documentElement.getProperty(i-1) as SoapObject

                    var bus = Bus()
                    bus.MonitoredStopVisit_MonitoringRef = obj.getProperty("MonitoredStopVisit_MonitoringRef").toString()
                    bus.MonitoredVehicleJourney_LineRef = obj.getProperty("MonitoredVehicleJourney_LineRef").toString()
                    bus.MonitoredVehicleJourney_DirectionRef = obj.getProperty("MonitoredVehicleJourney_DirectionRef").toString()
                    bus.MonitoredVehicleJourney_PublishedLineName = obj.getProperty("MonitoredVehicleJourney_PublishedLineName").toString()
                    bus.MonitoredVehicleJourney_DestinationRef = obj.getProperty("MonitoredVehicleJourney_DirectionRef").toString()
                    bus.MonitoredVehicleJourney_DestinationName = obj.getProperty("MonitoredVehicleJourney_DestinationName").toString()
                    bus.MonitoredCall_ExpectedArrivalTime = obj.getProperty("MonitoredCall_ExpectedArrivalTime").toString()
                    bus.MonitoredCall_ExpectedDepartureTime = obj.getProperty("MonitoredCall_ExpectedDepartureTime").toString()

                    busList.add(bus)
                }
            } else {
                Log.v("**DEBUG**","busList size : " + busList.size.toString())
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

        return busList
    }
class Bus {
    lateinit var MonitoredStopVisit_MonitoringRef: String
    lateinit var MonitoredVehicleJourney_LineRef: String
    lateinit var MonitoredVehicleJourney_DirectionRef: String
    lateinit var MonitoredVehicleJourney_PublishedLineName: String
    lateinit var MonitoredVehicleJourney_DestinationRef: String
    lateinit var MonitoredVehicleJourney_DestinationName: String
    lateinit var MonitoredCall_ExpectedArrivalTime: String
    lateinit var MonitoredCall_ExpectedDepartureTime: String
}