Search code examples
c++web-servicesqtpointersgsoap

gSOAP deletes referenced values in objects after request finished


i'm using gSOAP to request information from a SOAP webservice

the soap webservice returns an object. i do the request in a calls called: "dataconnector"

in dataconnector i can output all values for the returned object but outside that all the referenced values in the object are null.

i did some searching and apperantly gSOAP deletes everything unless you remove in from the deallocation chain with soap_unlink()

i tried but it didn't help this is my code

any ideas of what i'm doing wrong?

QList<ns1__calls*> calls;

datacheckPortBindingProxy service;
ns1__getCalls request;
std::string un("4444");
request.username = &un;
ns1__getCallsResponse response;
if (service.getCalls(&request, &response) == SOAP_OK){
    qDebug() << "succesfull response";
    for(unsigned int i = 0; i< response.return_.size(); i++){
    ns1__calls* call = response.return_.at(i);

    qDebug() << QString(call->roomId->c_str());
    qDebug() << "      with type_id: " << (call->typeId-1) ;

    calls.append(call);
    soap_unlink(request.soap, call);
}

EDIT

nvm apperantly you need to unlink all the seperate values of the object

like this:

soap_unlink(response.soap, call->roomId);
soap_unlink(response.soap, call->display);
soap_unlink(response.soap, call->location);
soap_unlink(response.soap, call->staffAidId);
soap_unlink(response.soap, call->firstName);
soap_unlink(response.soap, call->lastName);

isn't there an eazier way?


Solution

  • This is not a specific gSOAP or web-services question. When the variable response gets out of scope, it deallocates the memory it has used and in my opinion you should really not unlink the memory gSOAP has reserved. If you unlink it, you are responsible for freeing it!

    The way to go is to make a copy of the objects referenced by the ns1__calls pointers.

    QList<ns1__calls> calls; // QList of instances instead of pointers
    ...
    calls.append(*call); // append a copy
    // soap_unlink(request.soap,call); // not needed!