GSOAP
≈ 5 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
gSOAP is a C and C++ software development toolkit for SOAP/XML web services and generic XML data bindings. Given a set of C/C++ type declarations, the compiler-based gSOAP tools generate serialization routines in source code for efficient XML serialization of the specified C and C++ data structures. Serialization takes zero-copy overhead.
gSOAP is a C and C++ software development toolkit for SOAP/XML web services and generic XML data bindings. Given a set of C/C++ type declarations, the compiler-based gSOAP tools generate serialization routines in source code for efficient XML serialization of the specified C and C++ data structures.
Serialization takes zero-copy overhead. //gsoap ns service namespace: tempuri //gsoap ns service style: document //gsoap ns service encoding: literal int ns__get_rate(char* hotel, int guests, float *rate); The last parameter of the function is always the service return value, which can be denoted as void for one-way operations and should be a struct/class to bundle multiple service return parameters. The function's int return value is used for error diagnostics.
A service invocation in C using the auto-generated soap_call_ns__get_rate function is executed as follows: const char *URL = "http://www.example.com/hotels"; const char *action = NULL; struct soap *ctx = soap_new(); // new context float rate; int err = soap_call_ns__get_rate(ctx, URL, action, "Happy Inn", 2, &rate); if (err == SOAP_OK && rate To facilitate web services implementations for legacy C and C++ systems, the prefix qualification of identifier names in C/C++ can be omitted or can be replaced by colon notation, for example ns:get_rate rather than ns__get_rate. The punctuation is removed in the auto-generated source code that is used in project builds.
A service invocation in C++ using the auto-generated Proxy class is executed as follows (using the Proxy's default endpoint URL and SOAP action values): Proxy proxy; float rate; int err = proxy.get_rate("Happy Inn", 2, &rate); if (err == SOAP_OK && rate By using annotations and identifier naming conventions, i.e. qualification with the prefix ns__ for the function ns__get_rate and by declaring properties of the ns namespace using the //gsoap directives in the example, a binding is established to web service operations. The auto-generated Web Services Description Language (WSDL) document declares a request message, a response message, and the get-rate operation portType interface and SOAP binding for the ns__get_rate function as follows: ... where the request and responses messages of the operation refer to XML elements that are defined in the types section of the WSDL as follows: Likewise, client and server C/C++ source code can be auto-generated from a set of WSDLs and XML schemas.
Services must be completed by defining the appropriate service operations. For example, the auto-generated C++ service class for this WSDL must be completed by defining the get_rate method as follows: int Service::get_rate(char *hotel, int guests, float *rate) { *rate = ... // determine the lodging rate of the hotel given the number of guests return SOAP_OK; } There are no restrictions on the type of the operation parameters that can be marshaled in XML for web service messaging, except that certain type declaration conventions and annotations should be followed to establish a data binding. //gsoap ns schema namespace: tempuri //gsoap ns schema form: qualified struct ns__employee_record { @char *xml__lang = "en"; @int ID = 9999; char *full_name 1:1; $int size 0:12; struct ns__employee_record *manages; }; where the following annotations and conventions are used: namespace qualification of types and members by identifier naming conventions: ns__employee_record, xml__lang attributes for members: @char*, @int default values for members: xml__lang = "en", ID = 9999 occurrence constraints in the form of minOccurs:maxOccurs for XML validation: full_name 1:1, size 0:12 dynamic arrays of element sequences consist of a pair of a special size field and an array pointer member: $int size; struct ns__employee_record *manages The gSOAP tools convert C/C++ data types to/from XML schema data types.
Since C does not support namespaces and struct/class member names cannot be namespace-qualified in C++, the use of identifier naming conventions in gSOAP allow for binding this structure and its members to an XML schema complexType that is auto-generated as follows: Furthermore, unions in a struct/class that are annotated with a special selector field for union member selection are mapped to/from schema choice particles, STL containers are mapped to/from sequence particles, enumerations are mapped to/from XML schema simpleType enumerations, and standard C/C++ primitive types are mapped to/from XSD types. For conversion of XSD schema to C/C++ data types, the actual mapping is configurable in gSOAP with a type mapping file.
An instance of the example hierarchical employee structure is serialized in XML as a tree by default, for example Jane Doe John Doe Bob Oz Alice Oz When the SOAP encoding style is enabled, the XML serialization in gSOAP respects co-referenced objects and cyclic data structures as per SOAP encoding rules resulting in XML with id-ref edges. The auto-generated XML data binding includes read and write operations to/from a file, string or stream.
For example, an ns__employee_record object has read and write operations: int soap_read_ns__employee_record(struct soap*, ns__employee_record*); int soap_write_ns__employee_record(struct soap*, const ns__employee_record*); To read an employee record from an XML file: struct soap *ctx = soap_new(); ctx->recvfd = open("employee.xml", O_RDONLY); if (ctx->recvfd) { ns__employee_record employee; if (soap_read_ns__employee_record(ctx, &employee) == SOAP_OK) ... close(ctx->recvfd); } soap_end(ctx); soap_destroy(ctx); // also deletes employee data soap_free(ctx); Parsed XML is internally validated against the data bindings' constraints. int soap_GET_ns__employee_record(struct soap*, const char *URL, ns__employee_record*); int soap_PUT_ns__employee_record(struct soap*, const char *URL, const ns__employee_record*); int soap_POST_send_ns__employee_record(struct soap*, const char *URL, const ns__employee_record*); int soap_POST_recv_ns__employee_record(struct soap*, ns__employee_record*); The POST functions should be called together, first a POST_send to transmit XML data to the endpoint URL followed by a POST_recv to accept the response data (may be of a different type). Received XML is internally validated against the data bindings' constraints.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1367652588 under CC BY-SA 4.0; modifications have been made.