gSOAP:不完整类型的无效使用 'struct SOAP_ENV__Header'

gSOAP: invalid use of incomplete type 'struct SOAP_ENV__Header'

我尝试从 SOAP 中获取一些数据 header 但我收到标题中记录的错误。

我使用 gSOAP 从 wsdl 文件创建正确的代码,即:

...
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
...

在生成的 MyNamespace_soap.h 中,您可以找到以下内容:

...
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_;
};
...

并在 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

最后但并非最不重要的一点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) {
      ...
    }
    ...

在我的代码中我这样写 (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
  ...
}      

...

编译器抛出:

... 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;

...

有人可以帮我解决这个问题吗?

我能够通过删除 wsdl2h 和 soapcpp2 命令中的一些选项(即 -q、-n 和 -N)来解决我的问题。这些选项定义 'WITH_NOGLOBAL' 但在存根文件中(见上文)结构仅在 'WITH_NOGLOBAL' 未定义时可用。

再次感谢您的建议