在Android Studio中使用kso​​ap出现非法属性错误

时间:2019-02-06 20:53:15

标签: java android soap android-ksoap2

我正在尝试使用kSoap库检索一些公交车站数据。以下是有关我要发出的请求的一些详细信息。 details

每当我尝试获得结果响应时,都会收到以下错误;

java.lang.RuntimeException: illegal property: GetRealTimeStopDataResult

这是我尝试检索RealTimeResult的尝试:

class CallWebService extends AsyncTask<String, Void, String> {
    @Override
    protected void onPostExecute(String s) {
        text.setText("Bus = " + s);
    }

    @Override
    protected String doInBackground(String... params) {
        SoapObject result;
        int i = 999;
        String resString = "";
        SoapObject soapObject = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setName(PARAMETER_NAME1);
        propertyInfo.setValue(params[0]);
        propertyInfo.setType(String.class);

        PropertyInfo propertyInfo1 = new PropertyInfo();
        propertyInfo1.setName(PARAMETER_NAME2);
        propertyInfo1.setValue("true");
        propertyInfo1.setType(String.class);

        soapObject.addProperty(propertyInfo);
        soapObject.addProperty(propertyInfo1);

        SoapSerializationEnvelope envelope =  new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(soapObject);

        HttpTransportSE httpTransportSE = new HttpTransportSE(URL);

        try {
            httpTransportSE.call(SOAP_ACTION, envelope);
            SoapObject soapPrimitive = (SoapObject) envelope.bodyIn;
            SoapObject body = (SoapObject) soapPrimitive.getProperty(0);
            resString = body.getProperty("GetRealTimeStopDataResult").toString();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return resString;
    }

引用的变量是;

String URL = "http://rtpi.dublinbus.ie/DublinBusRTPIService.asmx?WSDL";
String NAMESPACE = "http://dublinbus.ie/";
String SOAP_ACTION = "http://dublinbus.ie/GetRealTimeStopData";
String METHOD_NAME = "GetRealTimeStopData";
String PARAMETER_NAME1 = "stopId";
String PARAMETER_NAME2 = "forceRefresh";

编辑: 记录body.toString()会显示:

anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType{element=anyType{complexType=anyType{sequence=anyType{element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; }; }; diffgram=anyType{DocumentElement=anyType{StopData=anyType{ServiceDelivery_ResponseTimestamp=2019-02-06T21:14:18.243+00:00; ServiceDelivery_ProducerRef=bac; ServiceDelivery_Status=true; ServiceDelivery_MoreData=false; StopMonitoringDelivery_Version=1.0; StopMonitoringDelivery_ResponseTimestamp=2019-02-06T21:14:18.243+00:00; StopMonitoringDelivery_RequestMessageRef=anyType{}; MonitoredStopVisit_RecordedAtTime=2019-02-06T21:14:18.243+00:00; MonitoredStopVisit_MonitoringRef=4903; MonitoredVehicleJourney_LineRef=39; MonitoredVehicleJourney_DirectionRef=Inbound; FramedVehicleJourneyRef_DataFrameRef=2019-02-06; FramedVehicleJourneyRef_DatedVehicleJourneyRef=696; MonitoredVehicleJourney_PublishedLineName=39; MonitoredVehicleJourney_OperatorRef=bac; MonitoredVehicleJourney_DestinationRef=7339; MonitoredVehicleJourney_DestinationName=Burlington Road via Blanchardstown S.C.; MonitoredVehicleJourney_Monitored=true; MonitoredVehicleJourney_InCongestion=false; MonitoredVehicleJourney_BlockRef=39015; MonitoredVehicleJourney_VehicleRef=33598; MonitoredCall_VisitNumber=34; MonitoredCall_VehicleAtStop=false; MonitoredCall_AimedArrivalTime=2019-02-06T21:18:26+00:00; MonitoredCall_ExpectedArrivalTime=2019-02-06T21:18:26+00:00; MonitoredCall_AimedDepartureTime=2019-02-06T21:18:26+00:00; MonitoredCall_ExpectedDepartureTime=2019-02-06T21:18:26+00:00; Timestamp=2019-02-06T21:14:18.567+00:00; LineNote=anyType{}; }; StopData=anyType{ServiceDelivery_ResponseTimestamp=2019-02-06T21:14:18.243+00:00; ServiceDelivery_ProducerRef=bac; ServiceDelivery_Status=true; ServiceDelivery_MoreData=false; StopMonitoringDelivery_Version=1.0; StopMonitoringDelivery_ResponseTimestamp=2019-02-06T21:14:18.243+00:00; StopMonitoringDelivery_RequestMessageRef=anyType{}; MonitoredStopVisit_RecordedAtTime=2019-02-06T21:14:18.243+00:00; MonitoredStopVisit_MonitoringRef=4903; MonitoredVehicleJourney_LineRef=37; MonitoredVehicleJourney_DirectionRef=Inbound; FramedVehicleJourneyRef_DataFrameRef=2019-02-06; FramedVehicleJourneyRef_DatedVehicleJourneyRef=3984; MonitoredVehicleJourney_PublishedLineName=37; MonitoredVehicleJourney_OperatorRef=bac; MonitoredVehicleJourney_DestinationRef=7340; MonitoredVehicleJourney_DestinationName=Wilton Terrace via Castleknock; MonitoredVehicleJourney_Monitored=true; MonitoredVehicleJourney_InCongestion=false; MonitoredVehicleJourney_BlockRef=37008; MonitoredVehicleJourney_VehicleRef=44253; MonitoredCall_VisitNumber=4; MonitoredCall_VehicleAtStop=false; MonitoredCall_AimedArrivalTime=2019-02-06T21:32:53+00:00; MonitoredCall_ExpectedArrivalTime=2019-02-06T21:32:53+00:00; MonitoredCall_AimedDepartureTime=2019-02-06T21:32:53+00:00; MonitoredCall_ExpectedDepartureTime=2019-02-06T21:32:53+00:00; Timestamp=2019-02-06T21:14:18.583+00:00; LineNote=anyType{}; }; StopData=anyType{ServiceDelivery_ResponseTimestamp=2019-02-06T21:14:18.243+00:00; ServiceDelivery_ProducerRef=bac; ServiceDelivery_Status=true; ServiceDelivery_MoreData=false; StopMonitoringDelivery_Version=1.0; StopMonitoringDelivery_ResponseTimestamp=2019-02-06T21:14:18.243+00:00; StopMonitoringDelivery_RequestMessageRef=anyType{}; MonitoredStopVisit_RecordedAtTime=2019-02-06T21:14:18.243+00:00; MonitoredStopVisit_MonitoringRef=4903; MonitoredVehicleJourney_LineRef=39; MonitoredVehicleJourney_DirectionRef=Inbound; FramedVehicleJourneyRef_DataFrameRef=2019-02-06; FramedVehic

1 个答案:

答案 0 :(得分:0)

您应该首先在http://rtpi.dublinbus.ie/DublinBusRTPIService.asmx?WSDL处加载/转换WSDL(这不是端点URL,就像您的代码一样对待),以便为{{ 1}}回应;没有可用的SOAP文件时不建议使用泛型类(确实应该感谢这一类,因为它准确地描述了要使用的Web服务)。例如wsdl2ksoapSoapUI。还可以看到我添加的WDSL标签。

android-ksoap2似乎是终点,

没有http://rtpi.dublinbus.ie/DublinBusRTPIService.asmx ...,否则您可以张贴任何内容,并且始终会得到?WSDL

screenshot

产生这些类:

WSDL