Deep dive into java WebService

       Foreword: WebService is a mature technology at present, and its advantages and disadvantages are quite obvious. This article aims to get started with webService, explain its usage scenarios in detail, and analyze it with specific demos.

This article focuses on the following issues:

  • Advantages, disadvantages and usage scenarios of WebService?
  • Understand the basic concepts of WebService, what are Soap, WSDL, XML, HTTP, UDDI, and what role do they play in WebService?
  • How does the server publish the service, how does the client call the service, and what are the specific steps?

 1. Features and usage scenarios of WebService

       WebService is a very common remote invocation method, and its biggest advantage is that it is a cross-platform language, and it can be easily invoked whether the client is Java or .NET. It uses the SOAP (Simple Object Access Protocol) protocol to encapsulate the serialized message, which actually forms an xml file, which can be transmitted over the network through http. The client invocation of WebService actually uses the method of generating files, as long as you know the URL of the publishing interface, and there is no need to pass additional jar packages or class files.

      The main goal of WebServices is cross-platform interoperability .

       advantage:

  • Communication across firewalls: Generally, the Web server to be accessed and the client of the Web Service to be accessed are likely to be located behind the firewall, and other ports are closed by default and the HTTP port is opened, and the Web service is based on HTTP, so it can pass through the firewall. ;
  • Application integration: It can realize communication between different applications and applications developed on different system platforms. The biggest difference from RMI, DOCM, and CORBA is that Web Service uses SOAP as the basic communication protocol to avoid complex protocol conversion;
  • B2B Integration: Cross-company business transaction integration is often referred to as B2B integration. Through WebService, the company can "expose" key business applications to designated suppliers and customers. As long as the business logic is "exposed" to become WebService, any designated partner can call these business logic regardless of their business logic. What platform is the system running on and what development language is used. This greatly reduces the time and cost spent on B2B integration, making B2B integration accessible to many small and medium-sized businesses that would otherwise not be able to afford EDI.

        shortcoming:

  • Stand-alone application: As long as a stand-alone application communicates with other programs on the local machine, using WebService in this case consumes too much and will not bring any benefits;
  • Isomorphic applications for LANs: In short, a performance issue. As long as there are other methods that are more efficient and feasible than WebService from an application structure point of view, then don't use WebService.

2. First understanding of WebService

       First define WebService: WebService is a remote invocation technology across programming languages ​​and operating system platforms. There are two key points in the definition:

  • One is cross-language and cross-platform, indicating that it has a widely accepted protocol and is a standard. Similar to SQL, different languages ​​and platforms operate databases through SQL, and different languages ​​and platforms publish and use services through WebService. Sql carries data, and WebService carries services.
  • The second is remote invocation, indicating that it involves network communication, and the entire invocation process involves different modules and roles.

       The following first introduces the components and processes required to implement a complete WebService function. First picture above:

 

This picture describes the entire process of the complete WebService service and the entire process of publishing and calling the WebService. The general process is as follows:

  1. Service release: The service provider designs the service interface (function A) and implements it. After the local debugging is passed, it is released to the service registration center and registered with UDDI;
  2. Query service: When the service requester needs to use function A, it can query UDDI, and UDDI will return the service (WSDL) that can satisfy the requester;
  3. 分析服务:服务请求者收到UDDI反馈的WSDL服务描述信息,予以分析,生成客户端所需的模块准备发起WebService请求;
  4. 发起服务:分析WSDL服务描述,生成相应的SOAP消息,发送给服务提供者,以期待获得服务;
  5. 完成服务:服务提供者按SOAP消息执行指定的服务,并将服务结果反馈给请求者。
由上图和前面的流程介绍,WebService的体系结构及各自扮演的角色也很明确:
  • 服务提供者:即服务的提供者,它一直等待接收客户端的请求并反馈服务响应。(发布服务)
  • 服务请求者:即服务的使用者,它利用SOAP消息向服务提供者发送请求并获得服务。(使用服务)
  • 服务中介者:即UDDI,充当管理员的角色,其主要职责就是将服务请求者和合适的服务提供者联系起来,当然这个角色并不是必须的,尤其是客户端知道服务端的情况下。(绑定服务)
在了解WebService各模块及工作流程之后,我们接下来需要了解各模块之间如何交互,跨平台跨语言的协议标准是怎样的。
  • XML:(Extensible Markup Language)扩展型可标记语言。xml与语言无关、与平台无关,经常作为信息载体用于保存数据,是Soap的基础。
  • SOAP:(Simple Object Access Protocol)简单对象存取协议。是XML Web Service 的通信协议。当客户端通过UDDI找到服务WSDL描述文档后,它可以通过SOAP调用你建立的Web服务中的一个或多个操作。SOAP是XML文档形式的调用方法的规范,它可以支持不同的底层接口,像HTTP(S)或者SMTP,可以这样描述:SOAP=在HTTP的基础上+XML数据
  • WSDL:(Web Services Description Language) WSDL 文件是一个 XML 文档,用于说明一组 SOAP 消息:服务在什么地方(地址),提供什么样的方法(如何调用)。大多数情况下由软件自动生成和使用。
  • UDDI:(Universal Description, Discovery, and Integration) UDDI是一种根据描述文档来引导系统查找相应服务的机制。UDDI利用SOAP消息机制(标准的XML/HTTP)来发布,编辑,浏览以及查找注册信息。它采用XML格式来封装各种不同类型的数据,并且返回需要的数据。
 3、WebService样例输出

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326089919&siteId=291194637