在Android中为SoapWS创建正确的请求时遇到问题

时间:2018-10-10 10:53:23

标签: android soap android-ksoap2

我在使用kso​​ap2-android和v7.0 Android设备从Android创建对SOAP WS的正确请求时遇到问题。我已连接到服务,但响应显示请求中没有数据。我使用SoapUI来检查请求和响应,并且工作正常。这是我在SoapUI中使用的请求(由于NDA而省略了一些数据):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bus="http://path/to/file/busWS.wsdl">
   <soapenv:Header/>
   <soapenv:Body>
      <bus:synchronizeTime>
         <synchronizeTimeRequest>
            <bus-terminal>
               <BusCode>1</BusCode>
               <TerminalCode>1</TerminalCode>
               <CompanyCode>1</CompanyCode>
               <BusID>1</BusID>
               <TerminalID>1</TerminalID>
               <CompanyID>1</CompanyID>
               <VersionCode>1</VersionCode>
               <FilesVersion>1</FilesVersion>
               <NSerie>1</NSerie>
               <Signal>1</Signal>
               <Downloaded>1</Downloaded>
               <ProtocolVersion>1</ProtocolVersion>               
            </bus-terminal>
         </synchronizeTimeRequest>
      </bus:synchronizeTime>
   </soapenv:Body>
</soapenv:Envelope>

这也是在SoapUI中的响应:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:bus="http://path/to/file/busWS.wsdl">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <bus:synchronizeTimeResponse>
         <Time>20181010114431</Time>
         <bus-result>
            <Code>0</Code>
            <Message/>
         </bus-result>
      </bus:synchronizeTimeResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Android中的代码:

class TareaWSConsulta extends AsyncTask<String,Integer,Boolean> {

        private String resultString;
        @Override
        protected Boolean doInBackground(String... strings) {
            boolean resul = true;
            SoapObject busTerminal = new SoapObject(NAMESPACE,"busterminal");

            PropertyInfo busCode = new PropertyInfo();
            busCode.setName("BusCode");
            busCode.setValue("1");
            busCode.setType(String.class);
            busTerminal.addProperty(busCode);

            SoapObject example = new SoapObject(NAMESPACE,METHOD_NAME);
            example.addProperty(busCode);
            SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            env.setOutputSoapObject(example);


            HttpTransportSE httpTransport = new HttpTransportSE(URL);

            try {
                httpTransport.debug = true;
                httpTransport.call(SOAP_ACTION,env);
                Object result = env.getResponse();
                if (result == null){
                    Log.i(TAG,"Respuesta nula: ");
                }else {
                    Log.i(TAG, "Respuesta: " + result.toString());

                    Vector response = (Vector) result;
                    for (int i = 0 ; i < response.size() ; i++){
                        Log.i(TAG, "Respuesta: " + response.elementAt(i).toString());
                    }

                    SoapObject(NAMESPACE,"synchronizeTimeResponse");                    
                    Log.i(TAG, "Respuesta: " + resultString);
                }

            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }
            return resul;
        }

登录服务(目前在本地运行,也在远程检查):

"-----------------Terminal-------------------" 
"TerminalCode:, TerminalID:" 
"BusCode:, BusID:" 
"CompanyCode:, CompanyID:" 
"VersionCode:, NSerie:" 
"Signal:, Downloaded:" 
"ProtocolVersion:, FilesVersion:" 

如果代码正常工作,则日志应显示BusCode值,但该值为空。其余参数均已编码,但我省略了它们,因为尽管有足够的参数。知道我在做什么错吗?

0 个答案:

没有答案