XML / C ++类型绑定出错

时间:2018-03-17 10:45:46

标签: c++ gsoap

我有一个WSDL文件,我需要从中生成一个c ++ Web服务代码。我正在使用的工具链是gSOAP。

问题在于,生成的服务器类对于每个操作都有一个函数,其参数为char*,而不是ns2__something结构。如何强制gSOAP生成XML / C或XML / C ++绑定(根据我对gSOAP documentation的理解,它应该这样做[?])

WSDL文件:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="swus"
 targetNamespace="swus.wsdl"
 xmlns:tns="swus.wsdl"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:ns="urn:swus"
 xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
 xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
 xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
 xmlns="http://schemas.xmlsoap.org/wsdl/">

<types>

 <schema targetNamespace="urn:swus"
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:ns="urn:swus"
  xmlns="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="unqualified"
  attributeFormDefault="unqualified">
  <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>

    <element name="addRequestElement">
        <complexType>
            <sequence>
                <element name="a" type="xsd:double"></xsd:element>
                <element name="b" type="xsd:double"></xsd:element>
            </sequence>
        </complexType>
    </element>

    <element name="addResponseElement">
        <complexType>
            <sequence>
                <element name="result" type="xsd:double"></xsd:element>
            </sequence>
        </complexType>
    </element>

 </schema>
</types>

<message name="addRequest">
 <part name="parameters" element="addRequestElement"/>
</message>

<message name="addResponse">
 <part name="result" element="addResponseElement"/>
</message>

<portType name="calcPortType">
 <operation name="add">
  <input message="tns:addRequest"/>
  <output message="tns:addResponse"/>
 </operation>
</portType>

<binding name="swus" type="tns:calcPortType">
 <SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
 <operation name="add">
  <SOAP:operation style="document" soapAction=""/>
  <input>
     <SOAP:body use="literal" namespace="urn:swus" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </input>
  <output>
     <SOAP:body use="literal" namespace="urn:swus" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
  </output>
 </operation>
</binding>

<service name="swus">
 <port name="swus" binding="tns:swus">
  <SOAP:address location=""/>
 </port>
</service>

</definitions>

gSOAP参数:

wsdl2h -c++11 -g -a -w -y -oSWUS.h ../docs/service.wsdl
soapcpp2 -2 -S -a -A -t -c++11 -b -i ./SWUS.h

生成的代码段:

class SOAP_CMAC swusService : public soap {
  public: 
    /* blah blah blah... */
    /// Web service operation 'add' (returns SOAP_OK or error code)
    virtual int add(char *wsdl__addRequestElement, // =====>> Why?
                    char *wsdl__addResponseElement // =====>> Why?
    ) SOAP_PURE_VIRTUAL;
};

1 个答案:

答案 0 :(得分:4)

WSDL文件混合了两个名称空间(tnsswus)。

swus:添加到请求和响应元素类型:

<message name="addRequest">
 <part name="parameters" element="swus:addRequestElement"/>
</message>

<message name="addResponse">
 <part name="result" element="swus:addResponseElement"/>
</message>

gSOAP现在应该匹配正确的类型:

virtual int add(
  _ns2__addRequestElement *ns2__addRequestElement,
  _ns2__addResponseElement &ns2__addResponseElement
) SOAP_PURE_VIRTUAL;