What is WebServices

Source: Internet
Author: User

Search for jdni services in the same process
For example, weUse JNDI to find the datasource configured in TomcatThe Code is as follows:
Context context = new initialcontext ();
Datasource DS = (datasource) Context. Lookup ("Java:/COMP/ENV/jdbc/oracleds ");
Put the two lines of code on the JSP page. After new initialcontext (), the datasource can be found on the JNDI service.
This is becauseJSP and JNDI services are in the same process. But if it is not the same process, it cannot be new initialcontext ()
It is like the resources in the two rooms cannot be shared. Unless the walls are worn, the resources in the opposite room cannot be obtained.
Therefore, the main () method cannot effectively execute the two lines of code.
When running the main () method, it starts JVM to parse the class in a process, while Tomcat is another process.
Therefore, the JNDI service cannot be found between the two processes through the simple new initialcontext (). In fact, this process isRemote Call
In fact, remote connection does not mean that cross-machine or cross-network connection is remote connection,As long as it is a call between two processes, even if it is a remote call
That is to say, as long as it is not in the same JVM (more accurately, it is not in the same address space), it is a remote call.
That is to say, if we start two processes on the same machine and call each other, this process is already called remotely.

Basic Principles of distributed Communication
Mainly used on the clientStub (stub)AndSkeleton (skeleton)As an intermediary to implement distributed Communication
On the client, there will be something called a stub (stub,Its implementation adopts a very typical proxy mode, which is the proxy of remote objects on the client.
Stub encapsulates the access details (how to compress, compress, and encode) of the interactive data, and then usesProtocolExchange data with skeleton (skeleton)
For distributed Communication Technology in the Java field, the most common ones are EJB technology, CORBA technology, and WebService technology.
If yesEJBTechnology, Stub will adoptRMI-IIOP protocolsTo send data to skeleton.
If yesCORBATechnology, Stub will adoptIIOP protocolTo send data to skeleton.
If yesWebServicesTechnology, Stub will passSoap (Search) ProtocolTo send data to skeleton.
That is to say, Stub will send the information to skeletion according to the specific protocol.
Skeleton transfers stub data.Resolved to a specific language objectConcurrently send to remote object, that is, Server
For exampleThe server is developed in Java, so skeleton parses the received data into a Java object and then transmits it to the server.
Similarly, if the server is developed using C #, skeleton parses the received data into a C # object and then transmits it to the server.
Then the server will return the information to the client, so skeleton will compress and encode the information to be returned and send it to stub through the corresponding protocol.
Then stub unlocks the information transmitted by skeleton and sends it to the client. Therefore, the client obtains the returned information from the server.
The client object and remote object are located in different JVMs, or on different system platforms., That isDistributed Communication
It relies mainly on stub and skeleton for communication. To put it bluntly,Distributed communication: Communication Between stub and skeleton

Example of distributed Communication
Assume there are two servers,The local server is developed in Java.,Remote Server is a weather forecast developed using C #.The two can communicate in the following ways:
1,If the two do not use certain technologies for communication, it is also possible.
For example, the remote server opens a database table.And then the local serverUse JDBC to accessThis open database table can also implement distributed communication.
However, it is not good to open database tables.The structure and security of the table are not very good and not standard.
In addition, some data is not reflected by a single table,It may take some algorithms to calculate the result.
2,If bothWebServicesFor communication, you can use the SOAP protocol to exchange data. The data is transmitted using the HTTP protocol to XML files.
However, during the communication between the two parties,Because the SOAP protocol is used, the data exchanged between the two parties is a large text file (usually an XML file ).
In this case, there is a problem: If you need to request 10000 pieces of data, the size of the large text file to be exchanged will be very large, and the transfer process will be very time-consuming.
One solution is:Java can use its zip API to compress the XML file and then upload it to ftpserver.The server downloads the compressed XML file.
Then the server decompress the XML file, read it, and then process it accordingly,This is also one of the solutions to the extremely slow speed of transmitting large text files through the SOAP protocol.
3,The remote server can view the weather forecast data,Periodically report to an ftpserverAnd the client's Java program regularly retrieves data on the ftpserver.
4,The disadvantage of the third method is that it is not real-time.. We can alsoSend a message from the client to a remote server. The server listensAnd then send the message to the client.
5,BothAdopt pure IIOP (which belongs to the CORBA Technical Architecture) ProtocolTo communicate
6,If the remote server is developed using EJB, you canThrough RMI-IIOP protocolsCommunication.While the RMI-IIOP protocol uses binary transmission, the efficiency will be faster
BecauseEJB also applies the IIOP protocol of CORBA.Therefore, in the integration of heterogeneous systems, the interconnectivity of CORBA is better.
The procedure is roughlyThe server first injects the EJB into the JNDI tree, and then the client's Java program lookup the corresponding name on the JNDI treeIn this way, the EJB is passed.
That is to say, Stub will be dynamically transferred to the client's Java program, and then the client will call stub, followed by stub and skeleton.
In additionEJB can only be written in Java, but it can be called using the CORBA technology.

Native of EJB
In ejb1.x, the support for Distributed communication services is poor.
For example, if you want to write an EJB, you must write at least three classes and then compile them,Compiled into stub and skeletonIn this case, five or six classes will be compiled.
Later, it was improved,The first change is JBoss.. This person who develops JBoss's EJB container is a very powerful person in Java technology.
HeIntroduce JDK dynamic proxy to automatically generate stubSo the development of EJB is simpler. Only three classes can be written, and the stubs will be generated at runtime.
That is, after the EJB is injected into the JNDI, we can look up the JNDI name in another JVM to get the EJB
Then it willSerializes and transmits ejbs to the client.,It transmits stub, which is invisible in the JVM memory.
When we call the corresponding method on the client,In fact, Stub is called in the memory, and stub then deals with the remote end.

WebServices-communication between heterogeneous systems
In terms of standards,The entire technical architecture is WebServices (with S), Sometimes you will see many people writeWebService (without S) is actually not standard
WebService refers to a separate service, while WebServices refers to its technical architecture.
Currently, WebServices is more widely used,Because it uses the HTTP protocol, it can traverse the firewall, and it can naturally traverse port 80.
HoweverThe disadvantage of WebServices is: Slow !!Because WebServices are transmitted over HTTPLarge textThe actual transfer is an XML file.
WhileIIOP (which belongs to the CORBA Technical Architecture) ProtocolWhat is transmittedBinaryTherefore, it is much more efficient than WebServices.
Therefore, in some industries, we also use a large number of CORBA technologies, such as telecommunication networks.
However, the disadvantage of CORBA is that the programming model is complex and belongs to the Heavyweight

Soap-Simple Object Access Protocol
Suppose we write a main () method locally in Java to deal with a remote service that can obtain weather forecasts written in any language.
If you are dealingIf WebServices technology is used, the XML file that is sent to the remote server uses the SOAP protocol.
Soap is a Simple Object Access Protocol.,The essence is HTTP + XMLIn other words, it transmits XML files through the HTTP protocol.
That is to say, soap is a simple XML-based protocol that enables applications to exchange information over HTTP.
Or, more simply, soap is the protocol used to access network services, and a SOAP message is a common XML document.
During the communication using the SOAP protocol, the remote object will form an XML file to be returned and send it to stub.
Then the client converts the XML file to a Java object. When the client calls the remote service
The client will convert the Java object to an XML file and pass it to skeleton as the parameter. skeleton will convert the XML file to the corresponding language object of the remote service.
For exampleThe server is developed in Java, so skeleton parses the received data into a Java object.To the server.
Similarly, if the server is developed using C #, skeleton parses the received data into a C # object and then transmits it to the server.
Therefore, WebServices can implement communication in heterogeneous languages and can be used to integrate heterogeneous systems.
Likewise,If it is not a heterogeneous system, there is no need to use WebServices Technology
For example, if both the client and remote objects are developed in Java, there is no need to use WebServices.
Because both of them are developed in Java, they can directly transmit data in binary format, and the access efficiency will be much faster.
In fact, WebServices is XML-based data exchange, that is, WebServices transmits large text, which naturally slows down the efficiency.
Unless our system is developed in multiple languagesSo you can consider using WebServices Technology
Or our system is designed to be more generic.WebServices can be used and opened.
In fact, soap is used to call Web Services.,While WSDL is used to describe how to use soap to call Web Services.

WSDL -- WebServices Description Language
The preceding example shows that the client is developed in Java and the server is a weather forecast service developed in C #.
As a client, it knows that the server provides a service that can obtain weather forecasts, and the client can also call this service.
However, as a server, you should describe these services to tell the client what services are available for calling.
This service cannot be described in C #, because clients developed using Java cannot recognize it.
Therefore, the server needs to use a set of languages to describe the services it provides. This language is the WSDL
In fact, WSDL is an XML file.That is to say, WebServices defines a set of standards in XML format.
This set of standards is used to describe External Services Provided by the server, such as C #'sMethod Name, parameter name, return value, and other information
Assume that the weather forecast function of the server has not been implemented using C #, and the client has not implemented using Java.
At this time, we suddenly asked to define a set of standards to describe the functions of the server's weather forecast to be implemented.
The client can call the weather forecast function at will,In this case, you can write a set of WSDL to describe the method name, parameter, return value, and other information.
When the server C # obtains the WSDL, it can generate the C # code through the WSDL, and then it can supplement the logic for obtaining the weather forecast function.
After the client-side Java obtains the WSDL, it can also generate Java code and then supplement the implementation of the corresponding agreed interface.
Some engines are needed to generate code in the corresponding language using WSDL.
For example, WebServices contains:Axis, cxf, xfireAnd other frameworks, they can be parsed into Java code according to the WSDL
Therefore, WSDL is a neutral language.
WhileThere is also something similar to WSDL In the CORBA architecture, called IDL.,Its syntax is similar to C ++, but IDL is not c ++

UDDI-discovery and integration services
Similar to JNDI. When the client looks for the services that the server can provide,You can ask for a UDDI request, and UDDI will send the WSDL to the client.
In fact, this process is generally not done through UDDI, but directly copying the WSDL. You can directly copy it by email or hard disk.
After the client obtains the WSDL, it can communicate with the remote server through the SOAP protocol.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.