CXF3.0.1解決方案:
配合spring方式java
<jaxws:endpoint id="receiveUMSMessageService" implementor="com.sw.extInterface.webservice.service.impl.ReceiveUMSMessageServiceImpl"
address="/ReceiveUMSMessageService" implementorClass="com.sw.extInterface.webservice.service.ReceiveUMSMessageService" />web
======================= old =====================
最近採用CXF寫了webservice接口,可是生成的wsdl卻沒有參數。spring
首先介紹一下JWS的註解:
Java Web Service (JWS) 註釋類型是 Web Service 的核心之一。url
(一)類級別spa
[b]@javax.jws.WebService(targetNamespace = "", name = "",serviceName = "") [/b]orm
targetNamespace :生成的 WSDL 中使用的名稱空間
name:Web Service 的名稱,映射到 WSDL 文件中的 <wsdl:portType> 元素
serviceName: Web Service 的服務名,映射到 WSDL 文件<wsdl:service> 元素。xml
[b]@javax.jws.soap.SOAPBinding(parameterStyle = javax.jws.soap.SOAPBinding.ParameterStyle.BARE) [/b]對象
用於指定 Web Service 到 SOAP 消息協議的映射。blog
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:definitions>