1、 术语描述:
1、web service:是一种远程调用的一种方案,是一种解决跨平台、跨语言间分布式系统的整合方案(socket),没有严格的客户端和服务端得界定
2、esb:enterprise service bus(企业服务总线)用于连接各系统的交互
3、soap:simple object access protocol 简单对象访问协议
4、soa:service oriented architecture 面向服务的架构(粗粒度)
5、wsdl :web service description language(web service 描述语言)
Xxx.wsd:web service 描述文档,描述web service服务信息的url,方法,参数等
使用JDK6开发一个webService的入门级例子:
准备工作:
1、建立一个普通的测试类(值得注意的是必须在某个包下)
2、JDK版本必须在jdk1.6u17或以上
例子如下非常简单:
package test;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
//定义一个WebService
@WebService
public class FirstWebService {
//此注解为对象提供的服务
@WebMethod
public String sayHello(String userName){
return "hello "+userName;
}
public static void main(String[] args) {
//设置此webService的访问路径
Endpoint.publish("http://localhost:8080/FirstWebService",new FirstWebService());
}
}
创建好此类后启动一个运行main方法,控制台信息为:
2011-7-10 23:03:16 com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
信息: Dynamically creating request wrapper Class test.jaxws.SayHello
2011-7-10 23:03:16 com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
信息: Dynamically creating response wrapper bean Class test.jaxws.SayHelloResponse
则成功部署,最后可以通过http://localhost:8080/FirstWebService?wsdl访问到此webService生成的wsdl文件,这样一个简单的helloWorld级得webService就建立成功了
值得一提的是假如你的JDK不是jdk1.6u17以上版本的话则会报
Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class test.jaxws.SayHello is not found. Have you run APT to generate them?
at com.sun.xml.internal.ws.model.RuntimeModeler.getClass(Unknown Source)
at com.sun.xml.internal.ws.model.RuntimeModeler.processDocWrappedMethod(Unknown Source)
at com.sun.xml.internal.ws.model.RuntimeModeler.processMethod(Unknown Source)
at com.sun.xml.internal.ws.model.RuntimeModeler.processClass(Unknown Source)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(Unknown Source)
at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(Unknown Source)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(Unknown Source)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(Unknown Source)
at javax.xml.ws.Endpoint.publish(Unknown Source)
at test.FirstWebService.main(FirstWebService.java:17)
要想解决的话建议替换JDK版本,如果确实不想替换版本那么解决方案是先用apt命令将主程序进行编译,然后生成一些java文件