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>