XML/C++ type binding goes wrong
Asked Answered
P

1

6

I have a WSDL file which I need to generate a c++ web service code from it. The toolchain I'm using is gSOAP.

The problem is that the generated server class, have a function for each operation with parameters as char* instead of something like ns2__something structs. How can I force gSOAP to generate XML/C or XML/C++ binding (according to my understanding of gSOAP documentation it should do so [?])

WSDL file:

<?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 parameters:

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

Generated code snippet:

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;
};
Photofinishing answered 17/3, 2018 at 10:45 Comment(0)
H
4

The WSDL file is mixing two namespaces (tns and swus).

Add swus: to the request and response element types:

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

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

gSOAP should match now the correct types:

virtual int add(
  _ns2__addRequestElement *ns2__addRequestElement,
  _ns2__addResponseElement &ns2__addResponseElement
) SOAP_PURE_VIRTUAL;
Herewith answered 23/3, 2018 at 17:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.