gSoap有多个WSDL

时间:2015-02-24 10:02:37

标签: c++ wsdl gsoap

我尝试使c ++代理形成多个WSDL,但生​​成的代理类具有错误的端点。代理类中每个方法的结果端点是一个连接值,如:

soap_endpoint = "http://endpoint1 http://endpoint2 etc".

跑完后:

wsdl2h.exe -o out\wsdl.h -t typemap.dat service1.wsdl service2.wsdl

结果wsdl.h有行:

//gsoap booking service name:   ricercaRichiestaSoap11 
//gsoap booking service type:   ricercaRichiesta 
//gsoap booking service port:   http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/ricercaRichiestaEsame/ 
//gsoap booking service port:   http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/stampaFoglioRosa/ 
//gsoap booking service namespace:  http://www.dtt.it/xsd/PrenotaPatenteWS 
//gsoap booking service transport:  http://schemas.xmlsoap.org/soap/http 

执行此命令后:

soapcpp2.exe -C -L -dout -j -x -I gsoap\import out\wsdl.h

它使用两种方法生成ricercaRichiestaSoap11Proxy类,但它们已加入端点:

soap_endpoint = "http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/ricercaRichiestaEsame/ http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/stampaFoglioRosa/";

如何解决这个问题?也许我必须使用不同的工作流来生成代理或手动编辑生成的wsdl.h? 感谢。


我在win7 x64上使用gSoap 2.8.17。

service1.wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:sch="http://www.dtt.it/xsd/PrenotaPatenteWS"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://www.dtt.it/xsd/PrenotaPatenteWS"
    targetNamespace="http://www.dtt.it/xsd/PrenotaPatenteWS">

  <wsdl:types> .... </wsdl:types>

  <wsdl:message name="ricercaRichiestaEsameResponse">
    <wsdl:part element="tns:ricercaRichiestaEsameResponse" name="ricercaRichiestaEsameResponse" />
  </wsdl:message>

  <wsdl:message name="ricercaRichiestaEsameRequest">
    <wsdl:part element="tns:ricercaRichiestaEsameRequest" name="ricercaRichiestaEsameRequest" />
  </wsdl:message>

  <wsdl:portType name="ricercaRichiesta">
    <wsdl:operation name="ricercaRichiestaEsame">
      <wsdl:input message="tns:ricercaRichiestaEsameRequest" name="ricercaRichiestaEsameRequest" />
      <wsdl:output message="tns:ricercaRichiestaEsameResponse" name="ricercaRichiestaEsameResponse" />
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="ricercaRichiestaSoap11" type="tns:ricercaRichiesta">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="ricercaRichiestaEsame">
      <soap:operation soapAction="" />
      <wsdl:input name="ricercaRichiestaEsameRequest">
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output name="ricercaRichiestaEsameResponse">
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <wsdl:service name="ricercaRichiestaService">
    <wsdl:port binding="tns:ricercaRichiestaSoap11" name="ricercaRichiestaSoap11">
      <soap:address location="http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/ricercaRichiestaEsame/" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

service2.wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:sch="http://www.dtt.it/xsd/PrenotaPatenteWS"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://www.dtt.it/xsd/PrenotaPatenteWS"
    targetNamespace="http://www.dtt.it/xsd/PrenotaPatenteWS">

  <wsdl:types> .... </wsdl:types>

  <wsdl:message name="stampaFoglioRosaResponse">
    <wsdl:part element="tns:stampaFoglioRosaResponse" name="stampaFoglioRosaResponse" />
  </wsdl:message>

  <wsdl:message name="stampaFoglioRosaRequest">
    <wsdl:part element="tns:stampaFoglioRosaRequest" name="stampaFoglioRosaRequest" />
  </wsdl:message>

  <wsdl:portType name="stampaFoglioRosa">
    <wsdl:operation name="stampaFoglioRosa">
      <wsdl:input message="tns:stampaFoglioRosaRequest" name="stampaFoglioRosaRequest" />
      <wsdl:output message="tns:stampaFoglioRosaResponse" name="stampaFoglioRosaResponse" />
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="stampaFoglioRosaSoap11" type="tns:stampaFoglioRosa">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="stampaFoglioRosa">
      <soap:operation soapAction="" />
      <wsdl:input name="stampaFoglioRosaRequest">
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output name="stampaFoglioRosaResponse">
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <wsdl:service name="stampaFoglioRosaService">
    <wsdl:port binding="tns:stampaFoglioRosaSoap11" name="stampaFoglioRosaSoap11">
      <soap:address location="http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/stampaFoglioRosa/" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

2 个答案:

答案 0 :(得分:2)

要从多个WSDL创建C ++代理以连接到不同的端点,您可以这样做:

  • 为每个WSDL生成头文件

    wsdl2h.exe -o out\Service1.h -t typemap.dat service1.wsdl

    wsdl2h.exe -o out\Service2.h -t typemap.dat service2.wsdl

  • 为每个标题生成代理类

    soapcpp2.exe -C -L -dout -j -x -I gsoap\import out\Service1.h

    soapcpp2.exe -C -L -dout -j -x -I gsoap\import out\Service2.h

  • 现在你有了

    Service1BindingProxy.h

    Service1BindingProxy.cpp

    Service2BindingProxy.h

    Service2BindingProxy.cpp

  • 为所有wsdl文件生成通用soap定义

    wsdl2h.exe -o out\CommonService.h -t typemap.dat *.wsdl

  • 生成常见的soap代码和命名空间映射

    soapcpp2.exe -C -L -dout -j -x -I gsoap\import out\CommonService.h

  • 你有

    soapH.h

    soapStub.h

    soapC.cpp

  • 只保留一个.nsmap文件。

  • 编译生成的soap代码,代理类和您的实现。

答案 1 :(得分:0)

  

“它使用两种方法生成ricercaRichiestaSoap11Proxy类,但它们已加入端点。”

之所以会这样,是因为WSDL使用相同的targetNamespace,这种情况很少见,不建议使用,因为这种情况下可能会导致冲突。切勿对不同的WSDL声明的服务使用相同的targetNamespace。在这种情况下,您将获得两个端点(端口),因为它们是为映射到booking名称空间前缀的同一targetNamespace定义的:

//gsoap booking service port:   http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/ricercaRichiestaEsame/ 
//gsoap booking service port:   http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/stampaFoglioRosa/ 

您始终可以使用代理调用本身来指定端点URL,例如proxy.stampaFoglioRosa("http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/stampaFoglioRosa/", NULL, ...params...),这将使代理连接到指定的端点URL。

或者,您可以按照@HAL的说明分别在WSDL上运行wsdl2h。但是您可能还希望通过wsdl2h选项-qNAME将C ++命名空间与这种方法结合使用。