对于一个项目,我必须在Windows平台上编写一个gsoap客户端。我正在使用MinGw g ++。 我使用-j选项生成代码,以便接收soap ... Proxy.h和.cpp文件
我想向我们的Web服务发送请求,其中输入( ns2 _getSMSByTimeSpan)和响应( ns2 _getSMSByTimeSpanResult)参数都是复杂类型。 输入参数包含另一个complexType(ns2__TimeSpan),它由2个time_t变量组成。在wsdl中,它被定义为xsd:dateTime。 我尝试 - 并且失败 - 设置这2个time_t变量。我只是不知道如何访问它。生成的文件中的注释并没有真正帮助我,我也无法通过谷歌搜索找到答案。
这是 ns2 _getSMSByTimeSpan和ns2__TimeSpan类在soapStub.h中的样子
class SOAP_CMAC _ns2__getSMSByTimeSpan
{
public:
std::string AccountKey; /* required element of type xsd:string */
ns2__TimeSpan *TimeSpan; /* required element of type ns2:TimeSpan */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 17; } /* = unique id SOAP_TYPE__ns2__getSMSByTimeSpan */
virtual void soap_default(struct soap*);
virtual void soap_serialize(struct soap*) const;
virtual int soap_put(struct soap*, const char*, const char*) const;
virtual int soap_out(struct soap*, const char*, int, const char*) const;
virtual void *soap_get(struct soap*, const char*, const char*);
virtual void *soap_in(struct soap*, const char*, const char*);
_ns2__getSMSByTimeSpan() { _ns2__getSMSByTimeSpan::soap_default(NULL); }
virtual ~_ns2__getSMSByTimeSpan() { }
};
class SOAP_CMAC ns2__TimeSpan
{
public:
time_t *StartDate; /* optional element of type xsd:dateTime */
time_t *EndDate; /* optional element of type xsd:dateTime */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 11; } /* = unique id SOAP_TYPE_ns2__TimeSpan */
virtual void soap_default(struct soap*);
virtual void soap_serialize(struct soap*) const;
virtual int soap_put(struct soap*, const char*, const char*) const;
virtual int soap_out(struct soap*, const char*, int, const char*) const;
virtual void *soap_get(struct soap*, const char*, const char*);
virtual void *soap_in(struct soap*, const char*, const char*);
ns2__TimeSpan() { ns2__TimeSpan::soap_default(NULL); }
virtual ~ns2__TimeSpan() { }
};
到目前为止我在做什么: 我正在创建一个gsoap类的实例,并创建并实例化我想要使用的complexTypes。
#include "soapSMSGateBindingProxy.h"
#include "SMSGateBinding.nsmap"
#include <iostream>
SMSGateBindingProxy instance;
ns2__TimeSpan *timeSpan;
size_t *timeSpanSize = new size_t;
*timeSpanSize = sizeof(ns2__TimeSpan);
timeSpan = (ns2__TimeSpan*)
soap_instantiate(instance.soap,
SOAP_TYPE_ns2__TimeSpan,"","",
timeSpanSize);
_ns2__getSMSByTimeSpan *smsByTimeSpan;
size_t *smsByTimeSpanSize = new size_t;
*smsByTimeSpanSize = sizeof(_ns2__getSMSByTimeSpan);
_ns2__getSMSByTimeSpanResult *smsResult;
size_t *smsResultSize = new size_t;
*smsResultSize = sizeof (_ns2__getSMSByTimeSpanResult);
smsByTimeSpan = (_ns2__getSMSByTimeSpan*)
soap_instantiate(instance.soap,
SOAP_TYPE__ns2__getSMSByTimeSpan,"","",
smsByTimeSpanSize);
smsResult = (_ns2__getSMSByTimeSpanResult*)
soap_instantiate(instance.soap,
SOAP_TYPE__ns2__getSMSByTimeSpanResult,"","",
smsResultSize);
delete smsByTimeSpanSize;
delete smsResultSize;
然后我尝试设置smsByTimeSpan-&gt; TimeSpan-&gt; StartDate值,但无论我尝试什么方法,客户端崩溃:
struct tm test;
test.tm_hour = 0; test.tm_min = 0; test.tm_sec = 0;
test.tm_year = 2013 - 1900; test.tm_mon = 8; test.tm_mday = 28;
// cout << mktime(&test) << timeSpan->StartDate << endl; //trying to access the StartDate value crashes it
// *smsByTimeSpan->TimeSpan->StartDate = mktime(&test);
// smsByTimeSpan->TimeSpan->soap_put(instance.soap, "2013-06-28 08:00:00", "2013-12-02 15:05:00");
// timeSpan.soap_put(instance.soap, "2013-12-02T14:10:03+02:00", "2013-12-02T14:50:03+02:00");
smsByTimeSpan->TimeSpan = timeSpan; //this works
*smsByTimeSpan->TimeSpan = mktime(&test); //this crashes
任何人都可以告诉我,我做错了什么?或者,告诉我如何正确地将数据输入timeSpan-&gt; StartDate值?
提前致谢
答案 0 :(得分:0)
好吧,我想我发现了,我做错了什么。当我创建这个问题时,我完全想错了方向...... 我的问题是指针。我通过将代码更改为:
来修复它time_t helper = mktime(&test);
smsByTimeSpan->TimeSpan = timeSpan;
timeSpan->StartDate = &helper;
就是这样。在寻找如何在gsoap中设置time_t类型时,也许有人可能仍然觉得这很有用。