前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >WebService

WebService

作者头像
用户1215919
发布于 2018-02-27 02:46:38
发布于 2018-02-27 02:46:38
1.6K00
代码可运行
举报
文章被收录于专栏:大大的微笑大大的微笑
运行总次数:0
代码可运行

Web Service概述:

    Web Service也叫XML Web Service。 WebService是一种轻量级的独立的通讯技术。是通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明。服务端提供服务供客户端调用, 具有夸平台跨语言的特性。

WSDL(Web Services Description Language):

    WSDL 文件是一个 XML 文档,webservice服务需要通过wsdl文件来说明自己有什么服务可以对外调用。并且有哪些方法、方法里面有哪些参数,  一般由程序自动生成。

    ①. 一个webservice对应唯一一个wsdl文档     ②. 定义webservice服务器端和客户端数据如何交换。

Soap (Simple Object Access Protocol)简单对象存取协议:

    是XML Web Service 的通信协议。webservice通过http协议发送和接收请求时, 发送的内容(请求报文)和接收的内容(响应报文)都是采用xml格式进行封装 , 这些特定的HTTP消息头和XML内容格式就是SOAP协议。

实例:

    服务端:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@WebService
public interface IProductRemote {
	@WebMethod
	String topup(String name);
}


//实现
@WebService
public class ProductImpl implements IProductRemote{

	@Override
	public String topup(String name) {
		return name + ",充值成功,请关注账户余额变更!";
	}

}

//发布
Endpoint.publish("http://127.0.0.1:8080/topup", new ProductImpl());
System.out.println("publish suc!");

//访问
http://127.0.0.1:8080/topup?wsdl

--------------------------------

通过wsimport -keep http://127.0.0.1:8080/topup?wsdl生成服务代码并引入client

客户端:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@WebService(name = "ProductImpl", targetNamespace = "http://impl.remote.ws.com/")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface ProductImpl {


    /**
     * 
     * @param arg0
     * @return
     *     returns java.lang.String
     */
    @WebMethod
    @WebResult(targetNamespace = "")
    @RequestWrapper(localName = "topup", targetNamespace = "http://impl.remote.ws.com/", className = "com.ws.remote.impl.Topup")
    @ResponseWrapper(localName = "topupResponse", targetNamespace = "http://impl.remote.ws.com/", className = "com.ws.remote.impl.TopupResponse")
    @Action(input = "http://impl.remote.ws.com/ProductImpl/topupRequest", output = "http://impl.remote.ws.com/ProductImpl/topupResponse")
    public String topup(
        @WebParam(name = "arg0", targetNamespace = "")
        String arg0);

}

//测试

ProductImplService service = new ProductImplService();
		ProductImpl remote = service.getProductImplPort();
		System.out.println(remote.topup("张三"));


控制台:
张三,充值成功,请关注账户余额变更!
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档