【发布时间】:2017-06-29 22:21:25
【问题描述】:
我正在为我的 Qt C++ 应用程序使用 gSoap 库来与一些基本的 Web 服务进行交互。
有没有办法从soap 对象中提取即将发送/(已接收)的完整 SOAP 请求/(响应)消息作为 XML 字符串? (用于教育目的)
我知道有 buf 成员,但那里的数据需要一些过滤,而且看起来不完整。
提前致谢。
【问题讨论】:
标签: c++ xml web-services soap gsoap
我正在为我的 Qt C++ 应用程序使用 gSoap 库来与一些基本的 Web 服务进行交互。
有没有办法从soap 对象中提取即将发送/(已接收)的完整 SOAP 请求/(响应)消息作为 XML 字符串? (用于教育目的)
我知道有 buf 成员,但那里的数据需要一些过滤,而且看起来不完整。
提前致谢。
【问题讨论】:
标签: c++ xml web-services soap gsoap
我需要使用这个插件,因为我想在我们的日志文件中记录 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 用户指南中有关于插件的部分:
【讨论】:
我相信 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) */
【讨论】:
您必须编写一个插件才能访问 XML 消息。看看插件目录下的pluging.h和pluging.c。
【讨论】: