gSoap - 将请求/响应提取为XML字符串

时间:2014-07-21 14:42:51

标签: c++ xml web-services soap gsoap

我正在使用gSoap库为我的Qt C ++应用程序与一些基本的Web服务进行交互。

有没有办法从soap对象中提取即将发送/(已收到)的完整SOAP请求/(响应)消息作为XML字符串? (用于教育目的)

我知道有buf成员,但数据需要进行一些过滤,看起来不完整。

提前致谢。

3 个答案:

答案 0 :(得分:3)

我需要使用这个插件,因为我想在我们的日志文件中记录xml消息。此插件显示了如何重定向fsend()和frecv()函数,这些函数发送和接收xml消息。

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;  
}  

gSOAP用户指南中有插件部分:

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

答案 1 :(得分:1)

我认为buf包含来自网络的XML数据,但不一定全部都是。

如果你想这样做,你最好在gsoap中启用调试日志记录(尽管你必须重新编译才能使其工作)。

取消注释stdsoap.h中的以下DEBUG语句,然后重新编译gsoap和您的应用程序。这将导致在应用程序的工作目录中生成非常方便的日志文件:

./stdsoap2.h:/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */

答案 2 :(得分:0)

您必须编写一个插件才能访问XML-Messages。看一下插件目录中的pluging.h和pluging.c。

相关问题