soap context is not being initialized for the code generated by gsoap engine when -p option is used.
Gsoap version : 2.8.108
Example:-
=========== wsdl=======
<complextype name="personalInfo">
<sequence>
<element name="name" type="xsd:string">
<element name="age" type="xsd:int">
</element></element></sequence>
</complextype>
========================
Generate soapStub using below command :-
wsdl2h -d -p -o soap.h above-sample.wsdl
soapcpp2 -j -x -C soap.h
====== soapStub.h =====
/ complex XML schema type 'ns2:personalInfo': /
class SOAP_CMAC ns2__personalInfo : public soap_dom_element {
public:
/// Required element 'name' of XML schema type 'xsd:string'
std::string name;
/// Required element 'age' of XML schema type 'xsd:int'
int age;
public:
/// Return unique type id SOAP_TYPE_ns2__personalInfo
virtual long soap_type(void) const { return SOAP_TYPE_ns2__personalInfo; }
/// (Re)set members to default values
virtual void soap_default(struct soap);
/// Serialize object to prepare for SOAP 1.1/1.2 encoded output (or with SOAP_XML_GRAPH) by analyzing its (cyclic) structures
virtual void soap_serialize(struct soap) const;
/// Output object in XML, compliant with SOAP 1.1 encoding style, return error code or SOAP_OK
virtual int soap_put(struct soap, const char tag, const char type) const;
/// Output object in XML, with tag and optional id attribute and xsi:type, return error code or SOAP_OK
virtual int soap_out(struct soap, const char tag, int id, const char type) const;
/// Get object from XML, compliant with SOAP 1.1 encoding style, return pointer to object or NULL on error
virtual void soap_get(struct soap, const char tag, const char type);
/// Get object from XML, with matching tag and type (NULL matches any tag and type), return pointer to object or NULL on error
virtual void soap_in(struct soap, const char tag, const char type);
/// Return a new object of type ns2__personalInfo, default initialized and not managed by a soap context
virtual ns2__personalInfo soap_alloc(void) const { return SOAP_NEW_UNMANAGED(ns2__personalInfo); }
public:
/// Constructor with default initializations
ns2__personalInfo() : name(), age() { }
virtual ~ns2__personalInfo() { }
/// Friend allocator used by soap_new_ns2__personalInfo(struct soap, int)
friend SOAP_FMAC1 ns2__personalInfo * SOAP_FMAC2 soap_instantiate_ns2__personalInfo(struct soap, int, const char, const char, size_t);
};
================
Implementation of soap_instantiate_ns2__personalInfo in soapC.cpp :-
SOAP_FMAC1 ns2__personalInfo * SOAP_FMAC2 soap_instantiate_ns2__personalInfo(struct soap soap, int n, const char type, const char arrayType, size_t size)
{
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "soap_instantiate_ns2__personalInfo(%p, %d, %s, %s)\n", (void)soap, n, type?type:"", arrayType?arrayType:""));
(void)type; (void)arrayType; / appease -Wall -Werror /
ns2__personalInfo p;
size_t k = sizeof(ns2__personalInfo);
struct soap_clist cp = soap_link(soap, SOAP_TYPE_ns2__personalInfo, n, soap_fdelete);
if (!cp && soap && n != SOAP_NO_LINK_TO_DELETE)
return NULL;
if (n < 0)
{ p = SOAP_NEW(soap, ns2__personalInfo);
// should have below line.
// p->soap = soap
}
else
{ p = SOAP_NEW_ARRAY(soap, ns2__personalInfo, n);
// iterate over the array and assign soap to each object
// p[i]->soap = soap;
k = n;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Instantiated ns2__personalInfo location=%p n=%d\n", (void)p, n));
if (size)
size = k;
if (!p)
soap->error = SOAP_EOM;
else if (cp)
cp->ptr = (void*)p;
return p;
}
==============================
shouldn't the passed soap context be assigned tp soap context of object created by SOAP_NEW?
Indeed. This was on the TODO list for too long. The 2.8.127 release will include the suggested code. This was tricky, because the soap_dom_element type is not visible to the analyzer so we need to make an exception and also deeper inheritance levels should be covered recursively.
Upcoming gsoap 2.8.127 has the code updated.