~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
简介
SOAP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
比较复杂,基于XML,有对应规范;REST利用HTTP请请求方式GET,POST,PUT,delete约定具体操作。简单的说,SOAP通过传输XML,XML定义了请求和响应的具体数据,要进行的操作等等.
REST
另一种约定,比如请求/user/100这个RUL,GET方式返回id为100的user信息,put方式则是更新id为1001的user信息,DELETE删除等。
接下来记录搭建cxf服务端
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1、pom.xml文件
4.0.0
com.jacky
cxf_demo
war
0.0.1-SNAPSHOT
cxf_demo Maven Webapp
http://maven.apache.org
junit
junit
3.8.1
test
javax
javaee-api
7.0
org.apache.cxf
cxf-rt-frontend-jaxws
2.6.1
org.springframework
spring-context
3.1.2.RELEASE
org.springframework
spring-web
3.1.2.RELEASE
org.apache.cxf
cxf-rt-transports-common
2.5.4
jar
compile
org.apache.cxf
cxf-rt-core
2.6.1
jar
compile
org.apache.cxf
cxf-rt-transports-http-jetty
2.6.1
jar
compile
org.apache.maven.plugins
maven-compiler-plugin
1.7
1.7
cxf_demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2、applicationContext.xml
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3、Info.java
packagecom.jacky.entity;public classInfo {privateString name;private intage;publicString getName()
{returnname;
}public voidsetName(String name)
{this.name =name;
}public intgetAge()
{returnage;
}public void setAge(intage)
{this.age =age;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4、GetInfoService.java
packagecom.jacky;importjavax.jws.WebMethod;importjavax.jws.WebParam;importjavax.jws.WebResult;importjavax.jws.WebService;importcom.jacky.entity.Info;
@WebService()public interfaceGetInfoService {
@WebMethod(operationName= "add")
@WebResult(name= "result")public int add(@WebParam(name = "number1") int number1, @WebParam(name = "number2") intnumber2);
@WebMethod(operationName= "getInfo")
@WebResult(name= "result")public Info getInfo(@WebParam(name = "name") String name, @WebParam(name = "age") intage);
}
5、GetInfoServiceImpl.java
packagecom.jacky.impl;importjavax.jws.WebService;importcom.jacky.GetInfoService;importcom.jacky.entity.Info;/** targetNamespace 的值是服务实现类的接口包的倒序,例如我的接口全路径为com.jacky.GetInfoService,则
* 名称空间为http://jacky.com/,否则,客户端动态调用会找不到方法
**/@WebService(endpointInterface= "com.jacky.GetInfoService",targetNamespace="http://jacky.com/")public class GetInfoServiceImpl implementsGetInfoService {
@Overridepublic int add(int number1, intnumber2) {return number1+number2;
}
@Overridepublic Info getInfo(String name, intage) {
Info info= newInfo();
info.setName(name);
info.setAge(age);returninfo;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6.web.xml
maven project
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml
CXFService
org.apache.cxf.transport.servlet.CXFServlet
CXFService
/cxf/*
到了这里就soap服务端就搭建好了,可以测试了
地址:http://www.localhost:8080/cxf_demo/cxf/getInfoService?wsdl
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
demo百度云地址:http://pan.baidu.com/s/1mikAGbA 密码:gpms