我以自頂向下的方式編寫了Web服務:我先寫了de WSDL,然後使用wsimport工具生成WS接口和代理,最後我寫了WS實現。 現在,我的WS被部署在Tomee 1.6服務器上,當我用?wsdl參數調用它時,我得到的WSDL與我之前寫的WSDL不同。在我的第一個WSDL中,服務名稱是「ImmoService」,而在調用部署的Web服務時獲得的WSDL是「ImmoServiceService」。WSDL從與用於生成Web服務的WSDL不同的Web服務獲得
我首先以爲這是Tomee的一個bug,所以我在Glassfish上部署了WS。但是我得到了同樣的結果。看來我錯過了一些東西。 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>
這裏是一個與WSDL參數
<?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>
這裏調用Tomee下我的WS時,我得到的是WSDL,我得到的時候我在Glassfish下調用我的WS:
<?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>
如果我建議使用我自己寫的WSDL生成一個客戶端,則此客戶端不起作用。它會得到以下錯誤: 「WS ImmoService無法訪問:無法在wsdl http:// localhost:8080/ImmoService/webservices/ImmoService?wsdl中找到名爲{http://ws.csf.fr/ImmoService}ImmoService的服務。 這是因爲真正的服務名稱不是ImmoService(我在WSDL中選擇的那個),而是ImmoServiceService(我可以在生成的WSDL中看到)。看來,所以我不能使用相同的WSDL來生成服務器和客戶端。這對我來說似乎很奇怪。 – jmb 2014-09-19 16:02:04
嘗試將@WebService(name =「ImmoServiceSoap」,serviceName =「ImmoService」,targetNamespace =「http://ws.csf.fr/ImmoService」,portName =「ImmoServiceSoap」)添加到您的服務impl中。這將解決它。 – mp911de 2014-09-19 18:04:40
它的工作原理。非常感謝 ! – jmb 2014-09-24 12:57:07