微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XML / C类型绑定出错

我有一个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;
};

解决方法

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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。