Web Services can convert applications into web applications.
By using Web Services, your application can publish information to the world or provide a feature.
Web Services can be used by other applications.
Web Services allows your accounting department's Win 2k server to connect to the IT vendor's UNIX server.
The basic Web Services platform is XML+HTTP.
Web services use XML to code data and use SOAP to transfer data.
What is webService
WebService, as the name suggests, is a Web-based service. It uses the Web (HTTP) method to receive and respond to some requests from external systems. This enables remote calls.
1: From the perspective of WebService's working mode, it is not essentially different from ordinary Web programs (such as ASP, JSP, etc.). They are programs based on HTTP transmission protocol.
2: The data used by WebService is based on XML format. Currently, the standard WebService mainly uses the SOAP protocol in data format. The SOAP protocol is actually a text protocol based on XML encoding specifications.
Technical support for webService
The Web Service platform requires a set of protocols to enable the creation of distributed applications. Any platform has its data representation method and type system. To achieve interoperability, the Web Service platform must provide a standard type system for communicating different types of systems in different platforms, programming languages, and component models. Currently these agreements include:
XML and XSD
Extensible markup language XML is the basic format for representing data in the Web Service platform. Besides being easy to build and analyze, the main advantage of XML is that it has nothing to do with the platform and the vendor. XML is created by the World Wide Web Association (W3C). XML SchemaXSD developed by W3C defines a standard set of data types and gives a language to extend this set of data types.
The Web Service platform uses XSD as the data type system. When you construct a Web Service in a language such as VB. NET or C#, in order to comply with the Web Service standards, all data types you use must be converted to XSD type. If you want it to be passed on between different platforms and different software, you also need to wrap it with something. This kind of thing is a protocol, such as SOAP.
SOAP
SOAP is the Simple Object Access Protocal, which is a lightweight protocol for exchanging XML encoding information. It has three main aspects: XML-envelope defines a framework for describing the information content and how to process the content, encodes program objects into XML objects, and executes the convention of remote procedure calls (RPC). SOAP can run on any other transport protocol. For example, you can use SMTP, the Internet email protocol, to deliver SOAP messages, which is very tempting. The headers are different between transport layers, but the XML payload remains the same.
Web Service hopes to achieve the ability of different systems to call each other in a "software-software dialogue" way, breaking the incompatible state between software applications, websites and various devices, and achieving the goal of "seasonable integration based on Web".
WSDL
Web Service Description Language WSDL is a formal description document provided in a machine-readable way and is based on XML. It is used to describe Web Service and its functions, parameters and return values. Because it is based on XML, WSDL is both machine-readable and human-readable.
UDDI
The purpose of UDDI is to establish standards for e-commerce; UDDI is a set of web-based, distributed, information registration center implementation standards and specifications provided for Web Services, and also includes a set of implementation standards that enable enterprises to register their own Web Services so that other enterprises can discover access protocols. Calling RPC and messaging
The Web Service itself is actually implementing communication between applications. We now have two ways of communication for applications: RPC remote procedure call and message delivery. When using RPC, the concept of a client is to call a remote procedure on the server. The usual way is to instantiate a remote object and call its methods and properties. The RPC system tries to achieve a kind of location transparency: the server exposes the interfaces of remote objects, and the client is like the interfaces of these objects used locally, thus hiding the underlying information, and the client does not need to know which machine the object is on.
How to publish a WebService?
1. Use Jdk1.6.0_21 later to publish a WebService service. And view its wsdl document through the address bar.
2. Generate client code through wsimport, call and view the results of the run. (Learn how to call is our focus).
It should be noted that when jdk1.6._07 is released after jdk version, the code must be fully annotated. If you are using jdk1.6.0_21, because it already contains ws2.1, you can only add @WebService annotations to the class.
Here are two different codes:
WS released on jdk1.6.0_13 version:
package com.itcast; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; import javax.xml.ws.Endpoint; @WebService(targetNamespace="http://loalhost:9999/helloworld") @SOAPBinding(style=Style.RPC)// Only support RPC message style public class HelloWorld { //The following is annotated by @WebMethod, the method @WebMethod public String saysHello(){ return "HelloWorld"; } public static void main(String[] args) { Endpoint.publish("http://localhost:9999/helloworld",new HelloWorld()); } } 2: The following is the WebService code released on jdk1.6.0_24:
package com.itcast; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService//Note that there is only this annotation, this annotation is also necessary. The default SOAP message style is: DOCUMENT public class HelloWorld { public String saysHello(){ return "HelloWorld"; } public static void main(String[] args) { Endpoint.publish("http://localhost:9999/helloworld",new HelloWorld()); } } The first WebService service
package com.itcast; import javax.jws.WebService; import javax.xml.ws.Endpoint; /** * The first WebService service application*/ //Or through annotation, indicate that this class is published as a WebService @WebService public class HelloWorld { public String saysHello(){ return "Hello World"; } //In the main method, use the javax.xml.ws.Endpoint endpoint to publish an application public static void main(String[] args) { Endpoint.publish("http://127.0.0.1:9999/helloworld", new HelloWorld()); } }Code Description: All non-static exposed methods of the HelloWorld class will be exposed to the outside.
Wsimport tool description:
WSimport is a tool that comes with jdk, and can generate client-side call code based on the wsdl document. Of course, no matter what language is written on the server-side WebService, Java code will be generated on the client. It doesn’t matter what is written on the server-side.
wsimport.exe is located in the JAVA_HOME/bin directory.
Common parameters are:
• -d<directory> - A .class file will be generated. Default parameters.
• -s<directory> - The .java file will be generated.
• -p<new package name generated> -Put the generated class under the specified package.
(wsdlurl) - http://server:port/service?wsdl, required parameters
use:
1: You can check your current version number through java version. If the version is too low, you can install a higher version of jdk.
Or directly copy the installed jdk directory to your machine such as D:/jdk1.6.0_24 directory.
Because the previous environment variables have been set to the previous old version of the jdk directory, namely the two environment variables JAVA_HOME and PATH.
You can reset the environment variable to: JAVA_HOME=D:/jdk1.6.0_24, path=%JAVA_HOME%/bin,
After resetting the environment variables, you must reopen a doc (command line) window to take effect.
If you do not want to modify the already configured environment variables, you can enter the following command in the command line window to make jdk1.6.0_24 take effect:
set path = D:/jdk1.6.0_24/bin;%PATH% (just enter)
Then check whether the version number of jdk has changed through java version.
2: Go to a relatively clean directory, I created a new directory name on the d disk called:ws, and go to this directory.
3: Turn on your webService.
4: Enter the following command:
wsimport s. http://127.0.0.1:9999/helloworld?wsdl
Parameter description: -s refers to the compilation of the source code file, and the following (point) refers to put it in the previous place.
The last http… refers to the address of obtaining the wsdl instruction manual.
5: At this time, the .java file and .class file will be generated. (both containing the original package name). Copy the code into your project. (only copy the java file)
6: In a new project, a new class (can be located under any package), call the code generated above, see ppt on the next page.
7: wsimport other parameters, the parameters we often use are -d, -s, -p
-d<directory> will generate .class files.
Example: wsimport d. http://127.0.0.1:9999/helloworld?wsdl
-s<directory> will generate .java file.
Example: wsimport s. http://127.0.0.1:9999/helloworld?wsdl
-p<package name> Modify the generated file (.java or .class to the specified package name)
Example: wsimport -s . -p com.beijing.itcast http://127.0.0.1:9999/helloworld?wsdl
For the -p parameter, pay attention to the modification of the package name. It places all generated classes under the package specified by -p. (Demo)
It should be noted that when only the -p parameter is used, it will also use -d at the same time to compile into a .class file. If the d parameter is written or not, it is there, and it will never leave.
The source code of RunMain.java is as follows:
package com.leaf; import com.itcast.HelloWorld; import com.itcast.HelloWorldService; /** * Call remote code by calling the generated class*/ public class RunMain { public static void main(String[] args) { //Return the call interface from the getHelloWorldPort method of HelloWorldSerice HelloWorld = new HelloWorldService().getHelloWorldPort(); String str = helloWorld.sayHello(); //Execute the call System.err.println(str);//Return HelloWorld string} }The difference between WebService and ordinary Web programs
1. WebService only uses HTTP POST to transmit data, and does not use GET;
1) The contentType of Tttp post is
(1) application/x-www-form-urlencoded
2) The contentType of WebService is
(2) Text/xml soap1.1
(3) application/soap+xml soap1.2
2. WebService is limited from the data transmission format.
The data used by WebService is based on XML format. Currently, the standard WebService mainly uses the SOAP protocol in data format. The SOAP protocol is actually a text protocol based on XML encoding specifications.
The difference between WebService and web server:
We can think of WebService as an application on a Web server; on the other hand, the Web server is a necessary container for the WebService runtime. This is their difference and connection.
Features of WebService:
1. WebService accepts customer requests through HTTP POST
2. The SOAP protocol is generally used between WebService and the client to transmit XML data.
3. It is designed for cross-platform or cross-language.