简体   繁体   English

具有多个WSDL的gSoap

[英]gSoap with multiple WSDLs

I try to make c++ proxies form multiple WSDLs, but generated proxy class has wrong endpoint. 我尝试使c ++代理形成多个WSDL,但是生成的代理类具有错误的端点。 Result endpoint for each method in proxy class is a joined value like: 代理类中每个方法的结果端点是一个联接值,例如:

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

After running: 运行后:

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

result wsdl.h has lines: 结果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 

After this command: 执行此命令后:

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

it generates ricercaRichiestaSoap11Proxy class with two methods but they has joined endpoint: 它使用两种方法生成ricercaRichiestaSoap11Proxy类,但它们已加入端点:

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

How to solve this issue? 如何解决这个问题? Maybe I have to use different workflow to generate proxies or manually edit generated wsdl.h? 也许我必须使用其他工作流程来生成代理或手动编辑生成的wsdl.h? Thanks. 谢谢。


I use gSoap 2.8.17 on win7 x64. 我在win7 x64上使用gSoap 2.8.17。

service1.wsdl: 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: 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>

To create C++ proxies from multiple WSDLs to connect to different endpoint, you could do this: 要从多个WSDL创建C ++代理以连接到不同的端点,可以执行以下操作:

  • Generate a header file for each WSDL 为每个WSDL生成头文件

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

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

  • Generate a proxy class for each header 为每个标头生成一个代理类

    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

  • Now you will have 现在你将有

    Service1BindingProxy.h

    Service1BindingProxy.cpp

    Service2BindingProxy.h

    Service2BindingProxy.cpp

  • Generate a common soap definition for all wsdl files 为所有wsdl文件生成通用的soap定义

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

  • Generate common soap code and namespace map 生成通用的Soap代码和名称空间映射

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

  • And you have 你有

    soapH.h

    soapStub.h

    soapC.cpp

  • Keep only one .nsmap file. 仅保留一个.nsmap文件。

  • Compile the generated soap code, proxy classes and your implementation. 编译生成的肥皂代码,代理类和您的实现。

"it generates ricercaRichiestaSoap11Proxy class with two methods but they has joined endpoint." “它使用两种方法生成ricercaRichiestaSoap11Proxy类,但它们已加入端点。”

This happens because the WSDLs use the same targetNamespace, which is rare and not recommended because it may result in clashes, like in this case. 发生这种情况是因为WSDL使用相同的targetNamespace,这种情况很少见,不建议使用,因为这种情况下可能会导致冲突。 Never use the same targetNamespace for different WSDL-declared services. 切勿对不同的WSDL声明的服务使用相同的targetNamespace。 In this case you get the two endpoints (ports) because they are defined for the same targetNamespace mapped to the booking namespace prefix: 在这种情况下,您将获得两个端点(端口),因为它们是为映射到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/ 

You can always specify an endpoint URL with the proxy invocation itself, such as proxy.stampaFoglioRosa("http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/stampaFoglioRosa/", NULL, ...params...) , which will let the proxy connect to the specified endpoint URL. 您始终可以使用代理调用本身指定终结点URL,例如proxy.stampaFoglioRosa("http://e-servizicoll.apps.dtt:80/PrenotaPatente-ws/services/stampaFoglioRosa/", NULL, ...params...) ,这将使代理连接到指定的端点URL。

Alternatively, you can run wsdl2h on the WSDLs separately as @HAL explained. 或者,您可以按照@HAL的说明分别在WSDL上运行wsdl2h。 But you may also want to use C++ namespaces with this approach using wsdl2h option -qNAME . 但是,您可能还想通过wsdl2h选项-qNAME将C ++命名空间与这种方法一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM