java wsdl 中不顯示引數屬性型別的問題解決方案
CXF3.0.1解決方案:
配合spring方式
<jaxws:endpoint id="receiveUMSMessageService" implementor="com.sw.extInterface.webservice.service.impl.ReceiveUMSMessageServiceImpl"
address="/ReceiveUMSMessageService" implementorClass="com.sw.extInterface.webservice.service.ReceiveUMSMessageService" />
======================= old =====================
最近採用CXF寫了webservice介面,但是生成的wsdl卻沒有引數。
首先介紹一下JWS的註解:
Java Web Service (JWS) 註釋型別是 Web Service 的核心之一。
(一)類級別
[b]@javax.jws.WebService(targetNamespace = "", name = "",serviceName = "") [/b]
targetNamespace :生成的 WSDL 中使用的名稱空間
name:Web Service 的名稱,對映到 WSDL 檔案中的 <wsdl:portType> 元素
serviceName: Web Service 的服務名,對映到 WSDL 檔案<wsdl:service> 元素。
[b]@javax.jws.soap.SOAPBinding(parameterStyle = javax.jws.soap.SOAPBinding.ParameterStyle.BARE) [/b]
用於指定 Web Service 到 SOAP 訊息協議的對映。
parameterStyle :確定方法引數是否表示整個訊息正文,或者引數是否是包裝在以操作命名的頂層元素中的元素。預設值:javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED
(二)方法級別
[b]@javax.jws.WebResult(name = "", targetNamespace = "", partName = "")[/b]
name:指定生成的 WSDL 中的操作結果的名稱, 預設名稱“return”。
[b]@javax.jws.WebMethod(operationName="") [/b]
operationName: 指定方法公開的公共操作名,對映到 WSDL 檔案中的 <wsdl:operation> 元素。沒有這個屬性的話,操作的公共名稱將與方法名相同。
[b]@javax.jws.WebParam(name="",targetNamespace="") [/b]
name: 指定輸入引數名,而不是該引數的Java 名稱“input”。
註釋描述部分轉載至:[url]http://suky.iteye.com/blog/692279[/url]
========================================
那麼為什麼引數型別不在wsdl上顯示呢?
原因就在targetNamespace上。
增加webservice interface和webservice impl的@webservice註解的targetNamespace屬性。
同時介面方法引數前@WebParam註解。
介面程式碼,實現類就不展示了
@WebService(targetNamespace="http://ucp.xxx.com")
public interface IMsgBusService {
/**
* 接收上行資料,DB資料儲存
* @param username 使用者
* @param password 密碼
* @param msgsObj 訊息物件
* @return 訊息狀態
*/
@WebMethod
Response showMsg(@WebParam(name = "username") String username,
@WebParam(name = "password") String password,
@WebParam(name = "msgsObj") MultiMessages msgsObj);
}
[color=red]注意:介面與實現類的targetNamespace屬性的值必須一致。[/color]
<?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://impl.service.bus.ucp.xxx.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://service.bus.ucp.xxx.com/" name="MsgBusServiceImpl" targetNamespace="http://impl.service.bus.ucp.xxx.com/">
<wsdl:import location="http://localhost/ucp/webservice/msgBusService?wsdl=IMsgBusService.wsdl" namespace="http://service.bus.ucp.xxx.com/">
</wsdl:import>
<wsdl:binding name="MsgBusServiceImplSoapBinding" type="ns1:IMsgBusService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="showMsg">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="showMsg">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="showMsgResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MsgBusServiceImpl">
<wsdl:port binding="tns:MsgBusServiceImplSoapBinding" name="MsgBusServiceImplPort">
<soap:address location="http://localhost/ucp/webservice/msgBusService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<?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://ucp.xxx.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="MsgBusServiceImpl" targetNamespace="http://ucp.xxx.com">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ucp.xxx.com" elementFormDefault="unqualified" targetNamespace="http://ucp.xxx.com" version="1.0">
<xs:element name="showMsg" type="tns:showMsg"/>
<xs:element name="showMsgResponse" type="tns:showMsgResponse"/>
<xs:complexType name="showMsg">
<xs:sequence>
<xs:element minOccurs="0" name="username" type="xs:string"/>
<xs:element minOccurs="0" name="password" type="xs:string"/>
<xs:element minOccurs="0" name="msgsObj" type="tns:multiMessages"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="multiMessages">
<xs:sequence>
<xs:element minOccurs="0" name="accessType" type="xs:string"/>
<xs:element minOccurs="0" name="id" type="xs:string"/>
<xs:element name="msgCount" type="xs:int"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="msgList" nillable="true" type="tns:multiMessage"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="multiMessage">
<xs:sequence>
<xs:element minOccurs="0" name="content" type="xs:string"/>
<xs:element minOccurs="0" name="description" type="xs:string"/>
<!-- ... ... -->
<xs:element minOccurs="0" name="destAgentId" type="xs:string"/>
<xs:element minOccurs="0" name="destination" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="showMsgResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:response"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="response">
<xs:sequence>
<xs:element minOccurs="0" name="message" type="xs:string"/>
<xs:element minOccurs="0" name="status" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="showMsg">
<wsdl:part element="tns:showMsg" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="showMsgResponse">
<wsdl:part element="tns:showMsgResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IMsgBusService">
<wsdl:operation name="showMsg">
<wsdl:input message="tns:showMsg" name="showMsg">
</wsdl:input>
<wsdl:output message="tns:showMsgResponse" name="showMsgResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MsgBusServiceImplSoapBinding" type="tns:IMsgBusService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="showMsg">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="showMsg">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="showMsgResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MsgBusServiceImpl">
<wsdl:port binding="tns:MsgBusServiceImplSoapBinding" name="IMsgBusService">
<soap:address location="http://localhost/ucp/webservice/msgBusService"/>
</wsdl:port>
</wsdl:service>
</wsdl:defin