java发布WebService接口的方式
WebService的基本概念WebService的特点和作用三要素WnbService接口的发布接口代码发布
WebService的基本概念
Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术。是:通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册。
WebService的特点和作用
WebService是一个SOA(面向服务的编程)的架构,它是不依赖于语言,不依赖于平台,可以实现不同的语言(通过 xml 描述)间的相互调用,通过Internet进行基于Http协议的网络应用间的交互。
三要素
WebService=WSDL+SOAP+UUID (webservice的注册)
SOAP=HTTP+XML,一个数据交换协议,客户端发送一个HTTP请求,这个HTTP请求中包含一个XML,服务端接收到到请求后解析这个XML来调用对应的服务和方法,返回对应的数据。
WSDL:描述XML文件里面的内容,服务端具体怎么调用,该传递什么参数,会返回什么类型的数据。
UUID:用于描述,发现,集成WebService
WnbService接口的发布
方式:JWS 通过java自带的JWS发布步骤 1. 在类上加上注解 2. 通过Endpoint发布
接口代码发布
@WebService
public class HelloWorld {
@WebMethod
public String sayHello(String str){
System.out.println("获取WenService接口方法sayHello");
String result = "Hello World, "+str;
return result;
}
public static void main(String[] args) {
System.out.println("server is running");
String address="http://localhost:9999/HelloWorld";
Object implementor =new HelloWorld();
Endpoint.publish(address, implementor);
}
}