WebService

I need to use it in recent projects For the knowledge of WebService, I found relevant information on the Internet and sorted it out.

1. Preface

Everyone has heard of WebService (Web Service) more or less. For a while, many computer journals, books, and websites have mentioned and promoted WebService technology wildly, and many of them boasted and advertised. But I have to admit that WebService is really a new and promising technology, so what is WebService? When should it be used?

Current The development of applications gradually showed two very different tendencies: one is a browser-based thin client application, the other is a browser-based rich client application (RIA), and then a technology relative It’s more fashionable (such as the very popular Html5 technology), here we mainly talk about the former.

Based on The thin client application of the browser is not because the thin client can provide a better user interface, but because it can avoid the high cost of publishing desktop applications. The cost of publishing desktop applications is high, half of which is due to application installation and configuration problems, and the other half is due to communication problems between the client and the server. Traditional Windows rich client applications use DCOM to communicate with the server and call remote objects. Configuring DCOM to work properly in a large network will be a very challenging task and a nightmare for many IT engineers. In fact, many IT engineers would rather endure the functional limitations brought by the browser than run a DCOM on the LAN. Regarding the communication between the client and the server, a perfect solution is to use the HTTP protocol to communicate. This is because any machine running a web browser is using the HTTP protocol. At the same time, many current firewalls are also configured to only allow HTTP connections. Many commercial programs also face another problem, that is, interoperability with other programs. If all applications are written in COM or .NET languages ​​and run on the Windows platform, then the world is peaceful. However, in fact, most commercial data is still stored in the form of non-relational files (VSAM) on the mainframe and accessed by mainframe programs written in COBOL. Moreover, there are still many commercial programs that continue to be written in C++, Java, Visual Basic and various 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 done by special methods, such as file transfer and analysis, message queues, and APIs that are only suitable for certain situations, such as IBM’s Advanced Program to Program Communication (APPC). In the past, there was no application communication standard that was independent of the platform, component model, and programming language. Only through the Web Service, the client and server can communicate freely with HTTP, no matter what the platform and programming language of the two programs are.

< /span>

Second, What exactly is WebService?

One In a nutshell: WebService is a cross-programming language and cross-operating system platform remote call technology.

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

The so-called Remote calling is the method by which a program on a computer a can call an object on another computer b. For example, UnionPay provides the POS card swiping system of a shopping mall, and the code of the transfer method called by the POS machine in the shopping mall is actually It runs on the bank server. For example, amazon, weather forecast system, Taobao, schoolnet, Baidu, etc. expose their system services in the form of webservice services, so that third-party websites and programs can call these service functions, which expands the market share of their systems Rate, blowing on the big concept, is the so-called SOA application.

Actually WebService can be understood from multiple angles. On the surface, WebService is an application that exposes an API that can be called through the Web to the outside world, which means that the application can be called through the Web by programming. We call the application that calls this WebService the client, and the application that provides this WebService is the server. From a deeper level, WebService is a new platform for establishing interoperable distributed applications, a platform, and a set of standards. It defines how applications can achieve interoperability on the Web. You can write Web services 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.

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

< /span>

3. WebService platform technology

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

XML +XSD:

WebService uses the HTTP protocol to transmit data, and uses XML format to encapsulate the data (that is, the XML indicates which method to call the remote service object, what parameters are passed, and what the return result of the service object is). XML is a format for representing data in the WebService platform. In addition to being easy to build and easy to 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 a competitor.

XML It solves the problem of data representation, but it does not define a set of standard data types, let alone how to extend this set of data types. For example, what does the integer number represent? 16-bit, 32-bit, 64-bit? These details are important to achieve interoperability. XML Schema (XSD) is a set of standards that specifically solves this problem. It defines a set of standard data types and gives a language to extend this set of data types. The WebService platform uses XSD as its data type system. When you use a certain language (such as VB.NET or C#) to construct a Web service, in order to comply with the WebService standard, all the 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.

SOAP :

When WebService sends requests and receives results through the HTTP protocol, the sent request content and result content are both encapsulated in XML format, and some specific HTTP message headers are added to illustrate the content format of the HTTP message. These specific HTTP message headers and XML The content format is the SOAP protocol. SOAP provides a standard RPC method to call Web Service.

SOAP Protocol = HTTP protocol + XML data format

The SOAP protocol defines the format of SOAP messages , SOAP protocol is based on HTTP protocol, SOAP is also based on XML and XSD, XML is SOAP data encoding method. To use an analogy: HTTP is an ordinary highway, XML is the green isolation belt in the middle and the protective fences on both sides, and SOAP is an ordinary highway that has been transformed with isolation belts and protective fences.

WSDL: p>

It’s like when we go to a store to buy things, we must first know what is available in the store, and then come to buy. The business practice is to post advertising posters. The same is true for WebService. The WebService client needs to call a WebService service. It must first know where the address of the service is and what methods can be called in this service. Therefore, the WebService server must first describe its home through a WSDL file. What service can be called externally, what is the service (what are the methods in the service, what are the parameters that the method accepts, and what is the return value), which url address represents the network address of the service, and how the service is called.

WSDL (Web Services Description Language) is such an XML-based The language used to describe the Web Service and its functions, parameters and return values. It is a standard format that both the WebService client and server can understand. 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 according to your Web service, but also import WSDL documents to generate proxy code for calling the corresponding WebService.

The WSDL file is saved on the Web server through a URL address You can access it. Before the client wants to call a WebService service, it needs to know the address of the WSDL file of the service. 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 by others; 2. Tell the client directly to the caller.

Four. WebService development

WebService development can be divided into server-side development and client-side development Two aspects of terminal development:

Server development: put the company The business methods of the internal system are published 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 Java WebService frameworks include axis, xfire, cxf, etc. Java ee servers usually also support publishing WebService services, such as JBoss.)< br> Client development: Invoke the WebService service published by others. The development that most people are engaged in belongs to this aspect, for example, invoking the weather forecast WebService service. (Use the manufacturer’s WSDL2Java and other tools to generate static call proxy code; use the client programming API class provided by the manufacturer; use the early standard jax-rpc development kit of SUN; use the latest standard jax-ws development kit of SUN .Of course SUN has been acquired by ORACLE)

WebService work call Principle: For the client, we pass the url address of the wsdl file to these various WebService client APIs, and these APIs will create the underlying proxy class. I call these proxies to access the webservice service. The proxy class converts the client’s method call to request data in soap format and then sends it through the HTTP protocol, and returns the received soap data as a return value. For the server side, the essence of various WebService frameworks is a big Servlet. When the client is remotely called to send request data in soap format through the http protocol, it analyzes the data and knows which java class to call Which method, then find or create this object, call its method, and then wrap the result returned by the method into soap format data, and send it back to the client through an http response message.

V. Applicable occasions

1, across firewall Communication:

If the application has thousands of users and is distributed all over the world, the communication between the client and the server will be a tricky problem. Because there is usually a firewall or proxy server between the client and the server. In this case, using DCOM is not that simple, and it is usually not easy to distribute client programs to such a large number of users. The traditional approach is to choose to use the browser as the client, write a lot of ASP pages, and expose the middle layer of the application to the end user. The result of this is that the development is difficult and the program is difficult to maintain. If the middle-tier components are replaced with WebService, the middle-tier components 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 layer, using the structure of WebService can save 20% of the development time spent on user interface programming.

2, application integration:

Enterprise-level application developers know that companies often have to write in different languages ​​and run on different platforms Various programs are integrated, and this integration will cost a lot of development effort. Applications often need to obtain data from programs running on the IBM mainframe; or send data to the mainframe or UNIX applications. Even on the same platform, various software produced by different software vendors often need to be integrated. Through WebService, you can easily integrate applications with different structures.

3, B2B integration:

Integrating applications with WebService can make the company’s internal business processes more automated. But what happens when the transaction crosses suppliers and customers and breaks the boundaries of the company? Cross-company business transaction integration is usually 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, by “exposing” the electronic ordering system and electronic invoice system, 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 Interchange) has long been like this. However, the implementation of WebService is much simpler than EDI, and WebService runs on the Internet and can be easily implemented anywhere in the world, and its operating 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 it can easily achieve interoperability. As long as the business logic is “exposed” and becomes a WebService, any designated partner can call these business logic, regardless of what platform their system runs on and what development language they use. This greatly reduces the time and cost spent on B2B integration, allowing many small and medium-sized enterprises that cannot afford EDI to 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. The most basic form is the reuse of source code modules or classes, and one form is the reuse of components in binary form. Using WebService applications can use standard methods to “expose” functions and data for use by other applications to achieve business-level reuse.

Reference: http://blog.csdn.net/wooshn/article/details /8069087

6. Not applicable occasions

1. Stand-alone application:

At present, companies and individuals still use many desktop applications. Some of them only need to communicate with other programs on the machine. In this case, it is best not to use WebService, just use the local API. COM is very suitable for working in this situation because it is small and fast. The same is true for server software running on the same server. It is best to directly use COM or other local APIs to make calls between applications. Of course, WebService can also be used in these occasions, but it will not only consume too much, and will not bring any benefits.

2. Isomorphic applications of LAN:

In many applications, all programs are developed with VB or VC, and all of them use COM under the Windows platform. All run on the same local area network. For example, there are two server applications that need to communicate with each other, or there is 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 a .NET program wants to connect to another .NET program on the local area network, you should use .NETremoting. Interestingly, in .NETremoting, you can also specify the use of SOAP/HTTP to make WebService calls. However, it is better to make RPC calls directly over TCP, which is much more effective.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3516 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.