gsoap complexTtype containing a complexType

837 views Asked by At

For a project, i have to write a gsoap client on a Windows platform. I'm using MinGw g++. I have generated the code using the -j option in order to receive the soap...Proxy.h and .cpp files

I want to send a request to our web service, where the input (ns2_getSMSByTimeSpan) and the response (ns2_getSMSByTimeSpanResult) parameters are both complex types. The input parameter contains another complexType (ns2__TimeSpan), which consists of 2 time_t variables. In the wsdl it's defined as xsd:dateTime. I try - and fail - to set those 2 time_t variables. I just don't know how to access it. The comments in the generated files didn't really help me and i also couldn't find an answer by googling.

This is what the classes ns2_getSMSByTimeSpan and ns2__TimeSpan look like in 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() { }
};

What i'm doing so far: I'm creating an instance of the gsoap class and create and instantiate the complexTypes i want to use.

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

Then i try to set the smsByTimeSpan->TimeSpan->StartDate value, but whatever approach i try, the client crashes:

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

Can anybody please tell me, what i do wrong? Or well, tell me how i correctly input data into the timeSpan->StartDate value?

Thanks in advance

1

There are 1 answers

0
surreal On BEST ANSWER

Ok, i think i found out, what i'm doing wrong. I totally thought in the wrong direction, when i created this Question... My problem was with pointers. I fixed it by changing my code to this:

time_t helper = mktime(&test);
smsByTimeSpan->TimeSpan = timeSpan;

timeSpan->StartDate = &helper;

and that was it. Maybe someone might still find this useful, when looking for how to set a time_t type in gsoap.