gpt4 book ai didi

java - 从 Web 服务获取的 WSDL 与用于生成 Web 服务的 WSDL 不同

转载 作者:行者123 更新时间:2023-11-30 03:45:08 25 4
gpt4 key购买 nike

我以自上而下的方式编写了一个Web服务:我首先编写了WSDL,然后使用wsimport工具生成WS接口(interface)和代理,最后编写了WS实现。现在,我的 WS 部署在 Tomee 1.6 服务器上,当我使用 ?wsdl 参数调用它时,我得到的 WSDL 与我第一次编写的不同。在我的第一个 WSDL 中,服务名称是“ImmoService”,而在调用已部署的 Web 服务时得到的 WSDL 中,它是“ImmoServiceService”。

我首先认为这是 Tomee 中的一个错误,因此我将 WS 部署在 Glassfish 上。但我得到了同样的结果。我好像错过了什么。 WS 生成的 WSDL 中的服务名称不应与生成 WS 的 WSDL 中的服务名称相同?

这是我首先编写的 WSDL:

<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:rp="http://ws.csf.fr/ImmoService"
targetNamespace="http://ws.csf.fr/ImmoService">
<types>
...
</types>

<!-- =========================================================================
Messages
========================================================================= -->
<message name="imprimerDocumentsSoapIn">
<part name="parameters" element="rp:imprimerDocuments"/>
</message>
<message name="imprimerDocumentsSoapOut">
<part name="parameters" element="rp:imprimerDocumentsResponse"/>
</message>

<!-- =========================================================================
PortType
========================================================================= -->

<portType name="ImmoServiceSoap">
<operation name="imprimerDocuments">
<input message="rp:imprimerDocumentsSoapIn"/>
<output message="rp:imprimerDocumentsSoapOut"/>
</operation>
</portType>

<!-- =========================================================================
Binding
========================================================================= -->
<binding name="ImmoServiceSoap" type="rp:ImmoServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="imprimerDocuments">
...
</operation>
</binding>

<!-- =========================================================================
Service
========================================================================= -->
<service name="ImmoService">
<port name="ImmoServiceSoap" binding="rp:ImmoServiceSoap">
<soap:address location="http://serveur:0/ImmoService/webservices/ImmoService"/>
</port>
</service>

</definitions>

这是我在 Tomee 下使用 ?wsdl 参数调用 WS 时得到的结果

<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.immoservice.csf.fr/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://ws.csf.fr/ImmoService" name="ImmoServiceService" targetNamespace="http://ws.immoservice.csf.fr/">
<wsdl:import location="http://vir-ws-int.csf.asso.fr:8080/ImmoService/webservices/ImmoService?wsdl=ImmoServiceSoap.wsdl" namespace="http://ws.csf.fr/ImmoService">
</wsdl:import>
<wsdl:binding name="ImmoServiceServiceSoapBinding" type="ns1:ImmoServiceSoap">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="imprimerDocuments">
<soap:operation soapAction="http://csf.fr/ImmoService/imprimerDocuments" style="document"/>
<wsdl:input name="imprimerDocuments">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="imprimerDocumentsResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ImmoServiceService">
<wsdl:port binding="tns:ImmoServiceServiceSoapBinding" name="ImmoServicePort">
<soap:address location="http://vir-ws-int.csf.asso.fr:8080/ImmoService/webservices/ImmoService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

这是我在 Glassfish 下调用 WS 时获得的 WSDL:

<?xml version='1.0' encoding='UTF-8'?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.3 (tags/2.3-7528; 2013-04-29T19:34:10+0000) JAXWS-RI/2.2.8 JAXWS/2.2 svn-revision#unknown. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.3 (tags/2.3-7528; 2013-04-29T19:34:10+0000) JAXWS-RI/2.2.8 JAXWS/2.2 svn-revision#unknown. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.immoservice.csf.fr/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.immoservice.csf.fr/" name="ImmoServiceService">
<import namespace="http://ws.csf.fr/ImmoService" location="http://localhost:8081/ImmoServiceService/ImmoService?wsdl=1"/>
<binding xmlns:ns1="http://ws.csf.fr/ImmoService" name="ImmoServicePortBinding" type="ns1:ImmoServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="imprimerDocuments">
<soap:operation soapAction="http://csf.fr/ImmoService/imprimerDocuments"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ImmoServiceService">
<port name="ImmoServicePort" binding="tns:ImmoServicePortBinding">
<soap:address location="http://localhost:8081/ImmoServiceService/ImmoService"/>
</port>
</service>
</definitions>

最佳答案

这是 Java SOAP 框架(Metro、CXF)的正常行为。即使您手动编写 WSDL、使用 wsimport 生成代码,然后使用 ?wsdl 获取生成的 WSDL,它们也始终会创建不同的 WSDL。某些框架允许您在公开服务时提供自己的 WSDL(请参阅 http://cxf.apache.org/docs/jax-ws-configuration.html Param wsdlLocation)

如果您有自己编写的 WSDL,请使用它来使用您的 WSDL 生成客户端和服务。不要使用生成的(这是我的经验)。您可以引用生成的 WSDL 以获得始终有效的端点,但不能用于更多。

关于java - 从 Web 服务获取的 WSDL 与用于生成 Web 服务的 WSDL 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25933988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com