webservice服务端实现

webservice服务端实现

- 引入
webservice只是一种思想,实现方式有很多种,jdk有默认实现。而且三方框架也有实现。
- webservice服务端的创建方步骤
1)创建项目
2)创建本地服务实现类

public class HelloMyFirstServiceImpl {
	public String helloService(String name){
		return name +"say: hello my first webservice!";
	}
}

3)把本地服务标记为远程服务
@WebService//标记为远程服务

 @WebService
public class HelloMyFirstServiceImpl {
	@WebMethod
	public String helloService(String name){
		return name +"say: hello my first webservice!";
	}
}

4)发布服务-根据注解来做一些事情

public static void main(String[] args) {
		// TODO Auto-generated method stub
		//Endpoint是终端的意思。
		String address = "http://192.168.1.11:8888/hello";//发布地址
		Object implementor = new HelloMyFirstServiceImpl();//发布服务
		Endpoint.publish(address, implementor);//异步执行
		System.out.println("服务发布成功!");
	}

5)测试
http://192.168.1.11:8888/hello?wsdl
注意事项:
1)jdk1.8不能直接访问服务地址,要加上?wsdl
2)没有保存,但是就不展示内容。浏览器兼容性问题。
3)localhost 127.0.0.1 局域网ip只要有一个成功就ok
- wsdl简介
1)wsdl是什么
web service description language 网络服务描述语句。简单的理解就是用来描述服务的。
2)结构讲解
definitions:根
name:服务名称,类型+Service
targetNamespace:http://倒置包名
service:服务接口
<soap:address location=“http://192.168.1.11:8888/hello”/>服务在哪个地址能够被访问
binding :
<soap:binding transport=“http://schemas.xmlsoap.org/soap/http” style=“document”/>
transport:一什么样传输协议来调用。
style=“document”:表示我们wsdl文件遵循什么格式 document/rpc
portType:接口类型
描述了有哪些接口方法
message:消息
描述接口方法的参数和返回值消息
types:描述消息的类型和名称-在document才有,而rpc没有

由上面的结构归纳得出下面的结论:
接口实现归纳法
接口:portType,message,types
实现:service,binding
3W归纳法:

where:service 在哪里调用?
how:binding 怎么调用?
what:portType,message,types 调用什么?
简单来说,就是wsdl描述服务有哪些方法,及在什么地址以什么样的方式能够被调用。

服务端的代码已上传至github
https://github.com/OsiyeA/The-Code-of-WebService.git

猜你喜欢

转载自blog.csdn.net/weixin_39446297/article/details/105458363