XML/C++类型绑定出现问题

6
我有一个WSDL文件,需要从中生成c++ web服务代码。我使用的工具链是gSOAP。
问题在于,生成的服务器类为每个操作拥有一个函数,参数为char*,而不是像ns2__something结构体。我该如何强制gSOAP生成XML/C或XML/C++绑定(根据我对gSOAP文档的理解,它应该这样做[?])。
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>
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个回答

4
WSDL文件混合了两个命名空间(tns和swus)。
在请求和响应元素类型中添加“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;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接