<beans xmlns=""http://www.springframework.org/schema/beans""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:jaxws=""http://cxf.apache.org/jaxws""
xsi:schemaLocation=""http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"">
<!—还需要引入以下3个关于CXF的资源文件,这三个文件在cxf.jar中-->
<import resource=""classpath:META-INF/cxf/cxf.xml"" />
<import resource=""classpath:META-INF/cxf/cxf-extension-soap.xml""/>
<import resource=""classpath:META-INF/cxf/cxf-servlet.xml"" />
…… …… …… …… …… …… …… …… …… ……
</bean>
3、 修改web.xml文件:
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
注意<url-pattern>/ services /*</url-pattern>配置,CXFServlet会拦截此类url,进行处理。
4、 写webservice接口:
package com.dqm.demo.service;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
import org.apache.cxf.annotations.EndpointProperty;
/**
* webservice接口
*
* @author dongqm
* @since 2013-2-26
* @lastChange $Author$
* @lastChangeDate $Date$
* @version $Rev$
*/
@WebService
public interface IHelloWorld {
@WebMethod(operationName = ""SayHelloWorld"")
@WebResult(name = ""result"")
public String sayHelloWorld(WebParam(name=""name"") String name);
}
| 级别 | 注解 | 参数 | 含义 |
| 类级别 | WebService(targetNamespace = "", name = "",serviceName = "") | targetNamespace | 生成的 WSDL 中使用的名称空间 默认为:接口所在的包的路径的反序 |
| name | Web Service 的名称 映射到 WSDL 文件中的 <wsdl:portType> 元素 默认为:接口名称 | ||
| serviceName | Web Service 的服务名 映射到 WSDL 文件<wsdl:service>元素。 默认为:接口名称 + "Service" | ||
| SOAPBinding(style = Style.RPC, use = Use.LITERAL) | style | 定义发送到 Web Service 的消息和从 Web Service 发送的消息的编码样式。 Document和RPC两种形式 默认值:javax.jws.soap.SOAPBinding.Style.DOCUMENT | |
| use | 定义发送到 Web Service 的消息和从 Web Service 发送的消息的格式样式。 ENCODED和 LITERAL两种形式 默认值:javax.jws.soap.SOAPBinding.Use.LITERAL | ||
| 方法级别 | WebResult(name = "", targetNamespace = "") | name | 指定生成的 WSDL 中的操作结果的名称 默认名称“return” |
| WebMethod(action="sayHello",operationName="") | action | 此操作的动作。 对于 SOAP 绑定,此方法可确定 soap 动作的值。 WSDL中: <soap:operation soapAction="" style="document"/> 默认为:"" | |
| operationName | 指定方法公开的公共操作名,映射到 WSDL 文件中的 <wsdl:operation> 元素 默认名称将与方法名相同 | ||
| WebParam(name="",targetNamespace="") | name | 指定输入参数名,而不是该参数的Java名称“input” 默认为方法参数名 |
package com.dqm.demo.service;
/**
* webservice接口实现类
*
* @author dongqm
* @since 2013-2-26
* @lastChange $Author$
* @lastChangeDate $Date$
* @version $Rev$
*/
public class HelloWorld implements IHelloWorld {
/*
* (non-Javadoc)
* @see com.dqm.demo.IHelloWorld#sayHelloWorld(String name)
*/
@Override
public String sayHelloWorld(String name) {
return name + ""Say:Hello World!"";
}
}
6、 Spring的配置文件中配置webservice:
<jaxws:endpoint address=""/Hello"" implementorClass=""com.dqm.demo.service.IHelloWorld"">
<jaxws:implementor>
<bean class=""com.dqm.demo.service.HelloWorld""/>
</jaxws:implementor>
</jaxws:endpoint>
注意:
①、address 为webservice发布的地址
②、implementorClass 为该webservice实现的接口
③、<jaxws:implementor></jaxws:implementor>之间定义的是implementorClass 指定接口的实现类
对于服务器端webService的暴露还有另一种方法(如下):
<jaxws:server id="helloWebService" serviceClass="com.dqm.demo.service.IHelloWorld"
address="/Hello">
<jaxws:serviceBean>
<ref bean="helloService"/>
</jaxws:serviceBean>
</jaxws:server>
| 元素 | 定义 |
| Types | 定义 web service 使用的数据类型。 为了最大程度的平台中立性,WSDL 使用 XML Schema 语法来定义数据类型。 |
| Message | 定义一个操作的数据元素。 每个消息均由一个或多个部件组成。可以把这些部件比作传统编程语言中一个函数调用的参数。 |
| PortType | 它可描述一个 web service、可被执行的操作,以及相关的消息。 可以把 <portType> 元素比作传统编程语言中的一个函数库(或一个模块、或一个类)。 |
| Operation | 对服务中所支持的操作的抽象描述,一般单个Operation描述了一个访问入口的请求/响应消息对 |
| Binding | 每个端口定义消息格式和协议细节。 |
| Service | 相关服务访问点的集合 |
| Port | 定义为协议/数据格式绑定与具体Web访问地址组合的单个服务访问点 |
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 引入以下3个关于CXF的资源文件,这三个文件在cxf.jar中 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:client id="helloServiceClient" serviceClass="com.dqm.demo.service.IHelloWorld"
address="http://localhost:8080/cxf_spring/services/Hello">
</beans>
/**
* @Title: HelloServiceClient.java
* @Package: com.dqm.demo.service
* @Project: cxf_spring
* @Description: TODO
* @author: Administrator
* @date: 2014-3-16 下午9:50:03
*/
package com.dqm.demo.service;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author: Administrator
* @Description:
*/
public class HelloServiceClient {
public static void main(String[] args) {
// 加载客户端的配置定义
ApplicationContext context = new ClassPathXmlApplicationContext(
"beanRefClient.xml");
// 获取定义的 Web Service Bean
IHelloWorld surveyService = (IHelloWorld) context
.getBean("helloServiceClient");
// 1、定义调查投票的变量与内容,用来发送给服务
String username = "Test";
int point = 88;
// 调用方法进行服务消费
String result = surveyService.sayHelloWorld(username);
System.out.println("Result:" + result);
// 2、传递不一样的调查投票内容
username = "Michael";
point = 100;
// 再次调用方法进行服务消费,得到不一样的结果
result = surveyService.sayHelloWorld(username);
System.out.println("Result:" + result);
// 3、第三次传递与调用
username = "Jordan";
point = 9;
result = surveyService.sayHelloWorld(username);
System.out.println("Result:" + result);
}
}
@WebResult(name = "return", targetNamespace = "")
@RequestWrapper(localName = "getNode", targetNamespace = "http://com.core.imact.sysgo.com/", className = "com.sysgo.imact.core.client.internal.com.GetNode")
@WebMethod
@ResponseWrapper(localName = "getNodeResponse", targetNamespace = "http://com.core.imact.sysgo.com/", className = "com.sysgo.imact.core.client.internal.com.GetNodeResponse")
public com.sysgo.imact.core.client.internal.com.NodeDTO getNode(
@WebParam(name = "arg0", targetNamespace = "") com.sysgo.imact.core.client.internal.com.GetNodeDTO arg0)
throws COMException;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getNodeDTO", propOrder = {
"id",
"parentFieldName",
"parentId"
})
public class GetNodeDTO {
。。。。。。。
返回的DTO也是如此。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "nodeDTO", propOrder = {
"ableToDelete",
"dbId",
"dirty",
"domainObject",
"fields",
"freezable",
"frozen",
"groupingElement",
"id",
"lockable",
"locked",
"name",
"notExpandable",
"parentFieldName",
"parentId",
"superTypeNames",
"transientNode",
"type",
"typeName"
})
public class NodeDTO {
而在服务器端中,
@Override
@WebMethod
public NodeDTO getNode(GetNodeDTO getNodeDTO) throws COMException {
return genericNodeService.getNode(getNodeDTO);
}
5808




被折叠的 条评论
为什么被折叠?



