Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of WebService

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "sample analysis of WebService", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "sample Analysis of WebService".

I. Preface

You have more or less heard of WebService (Web service). For a period of time, many computer journals, books and websites have mentioned and promoted WebService technology, including a lot of boasting and advertising components. But I have to admit that WebService is really a new and promising technology, so what on earth is WebService? When should I use it?

Current application development gradually presents two very different trends: one is browser-based thin client applications, and the other is browser-based rich client applications (RIA). Of course, the latter technology is relatively more fashionable (such as the popular Html5 technology). Here we focus on the former.

Browser-based thin client applications are not because thin clients can provide a better user interface, but because they can avoid the high cost of publishing desktop applications. Publishing desktop applications is expensive, partly because of questions about application installation and configuration, and partly because of communication problems between the client and the server. Traditional Windows rich client applications use DCOM to communicate with the server and invoke remote objects. Configuring DCOM to work properly in a large network will be a challenging task and a nightmare for many IT engineers. In fact, many IT engineers would rather put up with the functional limitations of browsers than run a DCOM on a local area network. A perfect solution to the problem of communication between client and server is to use HTTP protocol to communicate. This is because any machine running a Web browser is using the HTTP protocol. At the same time, many firewalls are currently configured to allow only HTTP connections. Many commercial programs also face another problem, which is interoperability with other programs. If all applications are written in COM or .NET and run on the Windows platform, the world will be at peace. In fact, however, most business data is still stored on mainframes as non-relational files (VSAM) and accessed by mainframe programs written in COBOL. Moreover, there are many commercial programs that continue to be written in C++, Java, Visual Basic and a variety of other languages. Now, except for the simplest programs, all applications need to integrate and exchange data with applications running on other heterogeneous platforms. Such tasks are usually accomplished by special methods, such as file transfer and analysis, message queuing, and API that are only applicable to certain situations, such as IBM's advanced program to program exchange (APPC). Previously, there was no application communication calibration that was independent of platform, build model, and programming language. Only through Web Service, the client and server are free to communicate with HTTP, regardless of the platform and programming language of the two programs.

What on earth is WebService

In a word: WebService is a remote calling technology across programming languages and operating system platforms.

The so-called cross-programming language and cross-operating platform means that server programs are written in java, client programs can be written in other programming languages, and vice versa! Cross-operating system platform means that server programs and client programs can run on different operating systems.

The so-called remote call is a method in which a program on one computer can call an object on another computer B. for example, the pos card swiping system provided by UnionPay to the mall, and the code of the transfer method called by the POS machine in the mall is actually running on the bank server. For example, amazon, weather forecast system, Taobao, Xiaonei, Baidu, etc., expose their system services in the form of webservice services, so that third-party websites and programs can call these service functions, thus expanding the market share of their own systems and blowing to a larger concept, that is, the so-called SOA applications.

In fact, WebService can be understood from many angles. On the surface, WebService is an application that exposes an API that can be called through Web, that is to say, the application can be called programmatically through Web. We call the application that calls this WebService the client, and the application that provides the WebService as the server. From a deep point of view, WebService is a new platform for building interoperable distributed applications, a platform and a set of standards. It defines how applications interoperate on Web. You can write Web service on any platform you like in any language you like, as long as we can query and access these services through the Web service standard.

The WebService platform needs a set of protocols to realize the creation of distributed applications. Any platform has its own data representation and type system. To achieve interoperability, the WebService platform must provide a standard type system for communicating different types of systems in different platforms, programming languages, and component models. The Web service platform must provide a standard to describe Web service so that customers can get enough information to call the Web service. Finally, we must also have a way to make a remote call to this Web service, which is actually a remote procedure call protocol (RPC). In order to achieve interoperability, this RPC protocol must also be platform-independent and programming language independent.

III. WebService platform technology

XML+XSD,SOAP and WSDL are the three technologies that make up the WebService platform.

3.1 、 XML+XSD

WebService transmits data using HTTP protocol and encapsulates data in XML format (that is, XML specifies which method of the remote service object is called, what parameters are passed, and what is the return result of the service object). XML is the format for representing data in the WebService platform. In addition to being easy to build and analyze, the main advantage of XML is that it is both platform-independent and vendor-independent. Irrelevance is more important than technological superiority: software vendors will not choose a technology invented by competitors.

XML solves the problem of data representation, but it does not define a standard set of data types, let alone how to extend them. For example, what exactly does the shaping number represent? 16 bit, 32 bit, 64 bit? These details are important for interoperability. XML Schema (XSD) is a set of standards designed to solve this problem. It defines a standard set of data types and gives a language to extend them. The WebService platform uses XSD as its data type system. When you construct a Web service in a language such as VB.NET or C #, in order to comply with the WebService standard, all data types you use must be converted to XSD types. The tool you use may have automatically completed the conversion for you, but you are likely to modify the conversion process according to your needs.

3.2 、 SOAP

When WebService sends requests and receives results through HTTP protocol, the request content and result content are encapsulated in XML format, and some specific HTTP headers are added to explain the content format of HTTP messages. These specific HTTP headers and XML content formats are SOAP protocols. SOAP provides standard RPC methods to call Web Service.

SOAP protocol = HTTP protocol + XML data format

SOAP protocol defines the format of SOAP messages, SOAP protocol is based on HTTP protocol, SOAP is also based on XML and XSD, and XML is the data coding mode of SOAP. To make an analogy: HTTP is the ordinary highway, XML is the green barrier in the middle and the guardrail on both sides, and SOAP is the highway that has been rebuilt with the barrier and guardrail.

3.3 、 WSDL

For example, when we go to the store to buy something, we first need to know what is available in the store, and then come back to buy it. The merchant's approach is to put up advertising posters. WebService is the same. If a WebService client wants to call a WebService service, it must first know where the address of the service is and what methods can be called in the service. Therefore, the web service server should first use a WSDL file to indicate what service is available at home and what the service is (what methods are in the service, what parameters are accepted by the method, and what is the return value). The network address of the service is represented by which url address and how the service is invoked.

WSDL (Web Services Description Language) is such a XML-based language that describes Web Service and its functions, parameters, and return values. It is a standard format understood by both the WebService client and the server. Because it is based on XML, WSDL is both machine-readable and human-readable, which will be a great advantage. Some of the latest development tools can not only generate WSDL documents based on your Web service, but also import WSDL documents and generate proxy class code that calls the corresponding WebService.

The WSDL file is saved on the Web server and can be accessed through an url address. Before the client invokes a WebService service, it needs to know the address of the service's WSDL file. The WebService service provider can expose its WSDL file address in two ways: 1. Register to the UDDI server so that it can be found; 2. Tell it directly to the client caller.

IV. WebService development

WebService development can be divided into server-side development and client-side development.

4.1, server-side development

Publish the business methods of the company's internal system as WebService services for remote cooperation units and individuals to call. (with some WebService frameworks, you can easily publish your business objects as WebService services. Typical WebService frameworks for Java include axis,xfire,cxf, etc., and java ee servers usually support publishing WebService services, such as JBoss.)

4.2. Client development

Most people are engaged in the development of invoking WebService services published by others, such as invoking the weather forecast WebService service. (use tools such as manufacturer's WSDL2Java to generate proxy class code for static calls; use vendor-provided client-side programming API classes; use SUN's early standard jax-rpc development kit; use SUN's latest standard jax-ws development package. Of course, SUN has been acquired by ORACLE)

4.3. the principle of working call of WebService

For the client, we pass the url address of the wsdl file to the various WebService client API, and these API will create the underlying proxy class, and I can access the webservice service by calling these proxies. The proxy class changes the method call of the client into the request data in soap format and then sends it out through the HTTP protocol, and changes the received soap data into a return value. For the server, the essence of all kinds of WebService framework is a big Servlet. When the remote calling client sends it the request data in soap format through the http protocol, it analyzes the data and knows which method of which java class to call, so it goes to find or create the object, and calls its method, then wraps the result returned by the method into soap format data, and returns it back to the client through the http response message.

5. Applicable occasions

1. Communication across firewalls

If the application has thousands of users and is distributed around the world, the communication between the client and the server will be a thorny problem. Because there is usually a firewall or proxy server between the client and the server. In this case, using DCOM is not that easy, and it is usually not easy to distribute client programs to such a large number of users. Traditionally, you choose to use the browser as the client, write down a lot of ASP pages, and expose the middle layer of the application to the end user. The result is that the development is difficult and the program is difficult to maintain. If the middle-tier component is replaced with WebService, the middle-tier component can be called directly from the user interface. From the experience of most people, in an application with more interaction between the user interface and the middle tier, using the structure of WebService can save 20% of the development time on user interface programming.

2. Application integration

Enterprise application developers know that enterprises often have to integrate a variety of programs written in different languages and running on different platforms, and this integration will take a lot of development effort. Applications often need to get data from programs running on the IBM host, or send the data to the host or UNIX application. Even on the same platform, all kinds of software produced by different software vendors often need to be integrated. With WebService, applications of different structures can be easily integrated.

3. B2B integration

Integrating applications with WebService can make business processing within the company more automated. But what happens when the deal crosses the boundaries between suppliers and customers and the company? Cross-company business transaction integration is often called B2B integration. WebService is the key to successful B2B integration. Through WebService, companies can "expose" key business applications to designated suppliers and customers. For example, if the electronic order issuing system and electronic invoice system are "exposed", customers can send orders electronically, and suppliers can send raw material purchase invoices electronically. Of course, this is not a new concept. EDI (Electronic document Exchange) has been like this for a long time. However, the implementation of WebService is much simpler than EDI, and WebService runs on Internet and can be easily implemented anywhere in the world, so its running cost is relatively low. However, WebService is not a complete solution for document exchange or B2B integration like EDI. WebService is only a key part of B2B integration, and many other parts are needed to achieve integration.

The biggest advantage of using WebService to achieve B2B integration is that interoperability can be easily achieved. As long as the business logic is "exposed" as a WebService, it can be invoked by any designated partner, regardless of the platform on which their system runs or the development language they use. This greatly reduces the time and cost spent on B2B integration, so that many small and medium-sized enterprises that can not afford EDI can also achieve B2B integration.

4. Software and data reuse

Software reuse is a big topic. There are many forms of reuse, and the degree of reuse varies from big to small. The most basic form is source code module or class-level reuse, and one form is binary component reuse. Using WebService applications, functions and data can be "exposed" in a standard way for use by other applications to achieve business-level reuse.

VI. Inapplicable situations

1. Stand-alone application

At present, many desktop applications are still used by enterprises and individuals. Some of them only need to communicate with other programs on the local computer. In this case, it's best not to use WebService, just use the local API. COM is ideal for working in this situation because it is small and fast. The same is true of server software running on the same server. It is best to directly use COM or other local API to make calls between applications. Of course, WebService can also be used in these situations, but that is not only too expensive, but also will not bring any benefits.

2. Isomorphic applications of local area network

In many applications, all programs are developed in VB or VC, use COM under the Windows platform, and run on the same local area network. For example, there are two server applications that need to communicate with each other, or a Win32 or WinForm client program that wants to connect to another server on the LAN. In these programs, using DCOM is much more effective than SOAP/HTTP. Similarly, if one .NET program wants to connect to another .NET program on the LAN, you should use .NET remoting. Interestingly, in .NET remoting, you can also specify the use of SOAP/HTTP to make WebService calls. However, it is better to make a RPC call directly through TCP, which is much more effective.

The above is all the content of this article "sample Analysis of WebService". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report