Search code examples
c++xmlweb-servicessoapgsoap

gSoap - extracting request/response as XML string


I'm using the gSoap library for my Qt C++ application to interact with some basic web service.

Is there a way to extract the full SOAP request/(response) message that is about to be sent/(was received) from soap object as XML string? (for educational purposes)

I know that there is buf member but data there would require some filtering and it looks incomplete.

Thanks in advance.


Solution

  • I needed to use this plugin because I wanted to log the xml messages in our logfile. This plugin shows how to redirect the fsend() and frecv() functions, which send and receive the xml message.

    static int plugin_send(struct soap *soap, const char *buf, size_t len)  
    { 
      struct plugin_data *data = (struct plugin_data*)soap_lookup_plugin(soap, plugin_id);
    
      fwrite(buf, len, 1, stderr); //<--  pick up the xml from here!
    
      return data->fsend(soap, buf, len); /* pass data on to old send callback */  
    }  
    
    static size_t plugin_recv(struct soap *soap, char *buf, size_t len)  
    { 
      struct plugin_data *data = (struct plugin_data*)soap_lookup_plugin(soap, plugin_id);  
      size_t res = data->frecv(soap, buf, len); /* get data from old recv callback */ 
    
      fwrite(buf, res, 1, stderr); //<--  pick up the xml from here!
    
      return res;  
    }  
    

    There is section on plugin in the gSOAP User Guide:

    https://www.cs.fsu.edu/~engelen/soapdoc2.html#tth_sEc19.38