Trying to work with soap thanks to the Gsoap toolkit, I am trying the create a client and server.
I have generated the files necessary and now I would like call a function from the client to the server but I keep getting an "invalid argument" when writing the function. It surely is something "easy" that am I simply flying over but I can't seems to find why. Any help would be appreciated.
Code of the client :
Code:
#include "soapH.h"
#include "CentralSystemServiceSoap.nsmap"
const char *endpoint = "http://192.168.2.128:8080";
const char *localhost = "http://localhost:8080";
const char server[] = "http://192.168.2.128:8080";
int main(int argc, char **argv)
{
struct soap soap;
soap_init(&soap);
ns1__BootNotificationRequest BootNotificationRequest;
BootNotificationRequest.chargePointModel="1";
BootNotificationRequest.chargePointVendor="2";
ns1__BootNotificationResponse BootNotificationResponse;
//error here
soap_call___ns1__BootNotification (&soap,server,NULL,*BootNotificationRequest,&BootNotificationResponse);
if (soap.error)
std::cout << "error" << std::endl;
else
std::cout << "SOAP OK" << std::endl;
soap_destroy(&soap);
soap_end(&soap);
soap_done(&soap);
return SOAP_OK;
}
Here are how the function soap_call___ns1__BootNotification and the parameters type ns1__BootNotificationRequest and ns1__BootNotificationResponse are defined :
Code:
SOAP_FMAC5 int SOAP_FMAC6 soap_call___ns1__BootNotification(struct soap *soap, const char *soap_endpoint, const char *soap_action,ns1__BootNotificationRequest *ns1__bootNotificationRequest, ns1__BootNotificationResponse &ns1__bootNotificationResponse)
{ struct __ns1__BootNotification soap_tmp___ns1__BootNotification;
if (soap_endpoint == NULL)
soap_endpoint = "http://localhost/Ocpp/CentralSystemService/";
if (soap_action == NULL)
soap_action = "/BootNotification";
soap_begin(soap);
soap->encodingStyle = NULL;
soap_tmp___ns1__BootNotification.ns1__bootNotificationRequest = ns1__bootNotificationRequest;
soap_serializeheader(soap);
soap_serialize___ns1__BootNotification(soap, &soap_tmp___ns1__BootNotification);
if (soap_begin_count(soap))
return soap->error;
if (soap->mode & SOAP_IO_LENGTH)
{ if (soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put___ns1__BootNotification(soap, &soap_tmp___ns1__BootNotification, "-ns1:BootNotification", NULL)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap))
return soap->error;
}
if (soap_end_count(soap))
return soap->error;
if (soap_connect(soap, soap_url(soap, soap_endpoint, NULL), soap_action)
|| soap_envelope_begin_out(soap)
|| soap_putheader(soap)
|| soap_body_begin_out(soap)
|| soap_put___ns1__BootNotification(soap, &soap_tmp___ns1__BootNotification, "-ns1:BootNotification", NULL)
|| soap_body_end_out(soap)
|| soap_envelope_end_out(soap)
|| soap_end_send(soap))
return soap_closesock(soap);
if (!&ns1__bootNotificationResponse)
return soap_closesock(soap);
ns1__bootNotificationResponse.soap_default(soap);
if (soap_begin_recv(soap)
|| soap_envelope_begin_in(soap)
|| soap_recv_header(soap)
|| soap_body_begin_in(soap))
return soap_closesock(soap);
ns1__bootNotificationResponse.soap_get(soap, "ns1:bootNotificationResponse", NULL);
if (soap->error)
return soap_recv_fault(soap, 0);
if (soap_body_end_in(soap)
|| soap_envelope_end_in(soap)
|| soap_end_recv(soap))
return soap_closesock(soap);
return soap_closesock(soap);
}
When I call this function I let the third argument NULL.
ns1__BootNotificationRequest :
Code:
class SOAP_CMAC ns1__BootNotificationRequest
{
public:
std::string chargePointVendor; /* required element of type ns1:ChargePointVendor */
std::string chargePointModel; /* required element of type ns1:ChargePointModel */
std::string *chargePointSerialNumber; /* optional element of type ns1:ChargePointSerialNumber */
std::string *chargeBoxSerialNumber; /* optional element of type ns1:ChargeBoxSerialNumber */
std::string *firmwareVersion; /* optional element of type ns1:FirmwareVersion */
std::string *iccid; /* optional element of type ns1:IccidString */
std::string *imsi; /* optional element of type ns1:ImsiString */
std::string *meterType; /* optional element of type ns1:MeterType */
std::string *meterSerialNumber; /* optional element of type ns1:MeterSerialNumber */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 21; } /* = unique type id SOAP_TYPE_ns1__BootNotificationRequest */
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*);
ns1__BootNotificationRequest() { ns1__BootNotificationRequest::soap_default(NULL); }
virtual ~ns1__BootNotificationRequest() { }
};
ns1__BootNotificationResponse :
Code:
class SOAP_CMAC ns1__BootNotificationResponse
{
public:
enum ns1__RegistrationStatus status; /* SOAP 1.2 RPC return element (when namespace qualified) */ /* required element of type ns1:RegistrationStatus */
time_t currentTime; /* required element of type xsd:dateTime */
int heartbeatInterval; /* required element of type xsd:int */
struct soap *soap; /* transient */
public:
virtual int soap_type() const { return 22; } /* = unique type id SOAP_TYPE_ns1__BootNotificationResponse */
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*);
ns1__BootNotificationResponse() { ns1__BootNotificationResponse::soap_default(NULL); }
virtual ~ns1__BootNotificationResponse() { }
};
I am betting it is something basic but I can't find it.
EDIT :
I was stupid, to solve it :
soap_call___ns1__BootNotification(&soap, server, NULL,&BootNotificationRequest, BootNotificationResponse);