Search code examples
c++soapgsoapsoapheader

gSOAP: invalid use of incomplete type 'struct SOAP_ENV__Header'


I try to get some data from a SOAP header but I receive the error written down in the title.

I used gSOAP to create the proper code from a wsdl file, i.e.:

...
wsdl2h -nMyNamespace -NMyNamespace -qMyNamespace -v -s -t ../gsoap_${GSOAP_VERSION}/typemap.dat -o MyNamespace_soap.h myWsdlFile.wsdl

soapcpp2 -n -pMyNamespace -qMyNamespace -I ../../gsoap/ -i -C MyNamespace_soap.h
...

In the generated MyNamespace_soap.h you can find the following:

...
class MyNamespace__HeaderContent {
  public:
    char* headerContent1 0;
    char* headerContent2 0;
    char* headerContent3 0;
    /// @todo <anyAttribute namespace="##any">.
    /// @todo Schema extensibility is user-definable.
    ///       Consult the protocol documentation to change or insert declarations.
    ///       Use wsdl2h option -x to remove this attribute.
    ///       Use wsdl2h option -d for xsd__anyAttribute DOM (soap_dom_attribute).
      @_XML __anyAttribute; ///< A placeholder that has no effect: please see comment.
    /// A handle to the soap struct context that manages this instance when instantiated by a context or NULL otherwise (automatically set).
    struct soap *soap;
};
...
mutable struct SOAP_ENV__Header {
  MyNamespace__HeaderContent*  MyNamespace__HeaderContent_;
};
...

and in MyNamespaceStub.h:

...
#ifndef WITH_NOGLOBAL
#ifndef SOAP_TYPE_MyNamespace_SOAP_ENV__Header
#define SOAP_TYPE_MyNamespace_SOAP_ENV__Header (150)
/* SOAP_ENV__Header: */
struct SOAP_CMAC SOAP_ENV__Header {
  public:
    /** Optional element 'MyNamespace:HeaderContent' of XSD type 'MyNamespace:HeaderContent' */
    MyNamespace__HeaderContent *MyNamespace__HeaderContent_;
  public:
    /** Return unique type id SOAP_TYPE_MyNamespace_SOAP_ENV__Header */
    int soap_type() const { return SOAP_TYPE_MyNamespace_SOAP_ENV__Header; }
    /** Constructor with member initializations */
    SOAP_ENV__Header() {
      MyNamespace__HeaderContent_ = (MyNamespace__HeaderContent *)0;
    }
    /** Friend allocator used by soap_new_SOAP_ENV__Header(struct soap*, int) */
    friend SOAP_FMAC1 SOAP_ENV__Header * SOAP_FMAC2 soap_instantiate_SOAP_ENV__Header(struct soap*, int, const char*, const char*, size_t*);
};
#endif
#endif

Last but not least MyNamespaceProxy.h:

...
#ifndef MyNamespaceProxy_H
#define MyNamespaceProxy_H
#include "MyNamespaceH.h"

namespace MyNamespace {

class SOAP_CMAC Proxy : public soap {
  public:
    ...
    Proxy(const char *endpoint);
    ...
    virtual int someServiceFunction(_MyNamespace__Request *MyNamespace__Request, _MyNamespace__Response &MyNamespace__Response) {
      ...
    }
    ...

In my code I wrote this (MyNamespace_service.cpp):

...
#include "MyNamespace_service.hpp"
#include "wsdl/MyNamespaceProxy.h"
#include "wsdl/MyNamespace.nsmap"
...
Proxy serviceProxy(config->MyServiceEndPointStr.c_str());
MyNamespace__HeaderContent *headerContent = NULL;

_MyNamespace__ServiceRequest request;
request.input1 = someVariable;
request.input2 = anotherVariable;

_MyNamespace__ServiceResponse response;

int soapReturn = serviceProxy.someServiceFunction(&request, response);

if (soapReturn == SOAP_OK) {
  ...
  SOAP_ENV__Header *soapHeader = serviceProxy.soap_header(); // this works 
  headerContent = soapHeader->MyNamespace__HeaderContent_; // this fails
  ...
}      

...

The compiler throws:

... error: invalid use of incomplete type ‘struct SOAP_ENV__Header’
headerContent = soapHeader->MyNamespace__HeaderContent_;
                          ^
In file included from src/some_service/wsdl/MyNamespaceStub.h:24:0,
    from src/some_service/wsdl/MyNamespaceH.h:16,
    from src/some_service/wsdl/MyNamespaceProxy.h:16,
    from src/some_service/MyNamespace_service.cpp:17:

./src/gsoap/stdsoap2.h:2577:10: note: forward declaration of ‘struct SOAP_ENV__Header’
    struct SOAP_ENV__Header *header;

...

Can somebody help me with this problem?


Solution

  • I was able to solve my problem by removing some of the options in the wsdl2h and soapcpp2 command (namely -q, -n and -N). These options define 'WITH_NOGLOBAL' but in the stub-file (see above) the struct is only avaiable if 'WITH_NOGLOBAL' is not defined.

    Thanks again for your suggestions