Hi,
I'm trying to use gsoap to generate server code from a WSDL, and I'm running
into troubles with generated class members of type std::string*, that are
generated for attributes. The constructor of the class containing this kind of
members has erroneous initializers, which triggers a compiler error.
Let me illustrate this with a snippet from the WSDL, followed by the generated
code:
<xsd:complexType name="PointOfSale">
<xsd:annotation>
<xsd:documentation>Point of Sale (POS) is the details identifying the
party or connection channel making the request. (source OTA)</x
sd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="CountryCode">
<xsd:annotation>
<xsd:documentation>2 character country code for the
representation of names of countries and their subdivisions</xsd:documentat
ion>
</xsd:annotation>
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="types:PointOfSaleCountryCodeType">
<xsd:attribute name="Agency" fixed="IATA / City Code
Directory" type="xsd:string"/>
<xsd:attribute name="URL"
fixed="http://www.iata.org/ps/publications/ccd.htm"
type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
gsoap generates the following code for this part of the WSDL:
class SOAP_CMAC _ns3__PointOfSale_CountryCode
{
public:
std::string __item;
std::string *Agency; /* optional attribute */
std::string *URL; /* optional attribute */
public:
virtual int soap_type() const { return 254; } /* = unique id
SOAP_TYPE__ns3__PointOfSale_CountryCode */
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*);
_ns3__PointOfSale_CountryCode() : Agency("IATA / City Code
Directory"), URL("http://www.iata.org/ps/publications/ccd.htm") {
}
virtual ~_ns3__PointOfSale_CountryCode() { }
};
As you can see, the std::string* members are not properly initialized.
I can get rid of the compiler errors by properly initializing the relevant
members, e.g.:
Agency( new std::string( "IATA / City Code Directory" ) )
But I'm not sure how this interferes with gsoap's memory management. If I
modify the initializers as above, I'd probably also have to write a destructor,
a copy constructor and an assignment operator (or make the latter two private,
and see wether it compiles).
But then again, since the data members are public, and any part of the
gsoap-generated code or the gsoap library may assign to the std::string*
members, I can't be sure not to leak memory without rigorous inspection of the
complete gsoap-generated code and library, which is not really feasible.
Alternatively, I could initialize the std::string* data members with
soap_new_std__string(soap, -1), but that requires a struct soap* argument,
which is not available in the constructor of the class above.
Finally, I could initialize all the std::string* data members to NULL, but then
I'd lose the default values.
Any advice would be appreciated.
Best regards,
René van Oostrum