0
votes

I want to send data to a WebService but it did not return a Feedback that worked and shows an error on a String. I am using KSOAP2.


When I debug, I get the following message:

Object has been collected Cannot evaluate org.ksoap2.serialization.SoapObject.toString()

If everything worked accordingly, it should answer me an 'OK', but the WebService returns a XML (responseDump):

< ?xml version="1.0" encoding="utf-8"?>< soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">< soap:Faultsoap:Server< /faultcode< faultstring>System.Web.Services.Protocols.SoapException: Server was unable to process request. --->System.InvalidOperationException: CommandText property has not been initialized. at System.Data.OracleClient.OracleCommand.get_StatementText() at System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals) at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor) at System.Data.OracleClient.OracleCommand.ExecuteNonQuery() at MettaWebService.BancoDados.executaComando(String query) at MettaWebService.MettaServicos.EnviarDados(String Query) at mobPrev_SAP.wsvmetta.EnviarDados(String Query) in c:\Users\Deivite\AppData\Local\Temp\Compilacao\wsvMetta_Eng\wsvmetta.asmx.cs:line 65--- End of inner exception stack trace ---


Here is code to send and receive the WebService:

public String transmitWS(String col_numero, String qtd_consumo, String idate_itime, String vlr_med,
                         String cod_valor, String matric, String texto_obs, String observacao,
                         String idProgramacao){
    String HOST = "";
    String NAMESPACE = "";
    String URL = "";              //all right here
    String SOAP_ACTION = "";
    String METHOD_NAME = "";

    String resultWS = null;

    SoapObject requestTransmit = new SoapObject(NAMESPACE, METHOD_NAME);
    PropertyInfo transmitPI = new PropertyInfo();
    transmitPI.setType(String.class);
    transmitPI.setName("Query");
    transmitPI.setValue("update prev_programacao set col_numero = " + col_numero + ", status_ponto = 3, qtd_consumo =" + qtd_consumo + "," +
            " idate_itime = TO_DATE('"+ idate_itime +"','YYYY-MM-DD HH24:MI:SS'), vlr_med = " + vlr_med + ", cod_valor = " + cod_valor +
            ", matric = " + matric +", texto_obs = '" + texto_obs + "', observacao = '" +
            observacao + "' where id_programacao = "+idProgramacao+"");
    requestTransmit.addProperty(transmitPI);
    SoapSerializationEnvelope envelopeTransmit = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelopeTransmit.dotNet = true;
    envelopeTransmit.setAddAdornments(false);
    envelopeTransmit.implicitTypes = false;
    envelopeTransmit.setOutputSoapObject(requestTransmit);
    HttpTransportSE androidHttpTransportTransmit = new HttpTransportSE(URL);
    //AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
    try {
        androidHttpTransportTransmit.debug = true;
        androidHttpTransportTransmit.call(SOAP_ACTION, envelopeTransmit);
        SoapObject responseTransmit = (SoapObject) envelopeTransmit.getResponse();
        resultWS = androidHttpTransportTransmit.requestDump;
        resultWS = androidHttpTransportTransmit.responseDump;

        Log.i("t", "doInBackground");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resultWS;
}

At the end, the resultWS is null. Does anyone know the cause of this error?

1

1 Answers

0
votes

I can't detect what's wrong, but here a a working function that uses ksoap. Maybe it will be of help:

    /**
 * Calls the stored proc on the server to return a dataset/SoapObject. This will always run the ProcReader method on the web server.
 * 
 * @param storedProc The Stored Proc to call
 * @param params The parameter(s) for the stored proc (pipe seperated for multiple parameters)
 * @return The SoapObject returned by the Stored Proc call
 * @throws Exception
 */
public static SoapObject callProcServiceForObject(String serviceMethod, String storedProc, String params) throws Exception {
    String NAMESPACE = "http://" + GlobalVars.serviceIP + "/";
    String METHOD_NAME = getMethodName(serviceMethod);
    String SOAP_ACTION = NAMESPACE + METHOD_NAME;
    String URL = "http://" + GlobalVars.serviceIP + "/ATService.asmx";
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    if (GlobalVars.encryptedService) {
        request.addProperty("ePassword", CryptUtil.encryptString(GlobalVars.deviceSerialNumber));
        request.addProperty("eData", CryptUtil.encryptString(GlobalVars.serverDB));
        request.addProperty("eSP_Name", CryptUtil.encryptString(storedProc));
        request.addProperty("eParam", CryptUtil.encryptString(params));
    } else {
        request.addProperty("sPassword", GlobalVars.deviceSerialNumber);
        request.addProperty("sData", GlobalVars.serverDB);
        request.addProperty("sSP_Name", storedProc);
        request.addProperty("sParam", params);
    }
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    // Enable the below property if consuming .Net service
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeout);
    //count up the network traffic
    numberOfBytesTransmitted = numberOfBytesTransmitted + StringToBytes(request.toString());

    SoapObject returnable = null;
    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        returnable = (SoapObject)envelope.getResponse();
    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("Msg:" + e.getMessage() + "; SP:" + storedProc + "; Params: " + params + "; Method:" + METHOD_NAME);
    }
    numberOfBytesTransmitted = numberOfBytesTransmitted + StringToBytes(returnable.toString());
    return returnable;
}