WebServices (i)

Source: Internet
Author: User
Tags http post soap wsdl

---completely from the network

What is WebService
WebService, as the name implies, is a web-based service. It uses the Web (HTTP) method to receive and respond to some kind of request from the external system. This allows for remote invocation.
1: From WebService's working mode, it is not fundamentally different from ordinary Web programs (such as ASP, JSP, etc.), and is based on the HTTP Transfer Protocol program.
The data used by 2:webservice is based on XML format. The current standard webservice mainly uses the SOAP protocol in the data format. The SOAP protocol is actually a text protocol based on XML encoding specification.
Technical support for WebService
The Web service platform requires a set of protocols for the creation of distributed applications. Any platform has its own data representation method and type system. To achieve interoperability, the WEB service platform must provide a standard set of type systems for communicating different types of systems in different platforms, programming languages, and component models. Currently these agreements are:
XML and XSD
Extensible Markup Language XML is the basic format for representing data in a Web service platform. In addition to being easy to establish and easy to analyze, the main advantage of XML is that it is platform-independent and vendor-independent. XML is created by the World Wide Web Association (SCHEMAXSD), which defines a standard set of data types and provides a language to extend this set of data types.
The WEB service platform uses XSD as the data type system. When you use a language such as VB. NET or C # to construct a Web service, all of the data types you use must be converted to the XSD type in order to conform to the Web service standard. If you want it to be passed between different organizations on different platforms and different software, you need to wrap it up with something. This kind of thing is a protocol, like SOAP.
Soap
Soap is a Simple Object Access Protocol (protocal), which is a lightweight protocol for exchanging XML encoded information. It has three main aspects: Xml-envelope defines a framework for describing information content and how to handle content, encodes program objects as rules for XML objects, and executes remote procedure call (RPC) conventions. Soap can run on any other transport protocol. For example, you can use SMTP, the Internet e-mail protocol, to pass SOAP messages, which is tempting. The headers between the transport layers are different, but the XML payload remains the same.
Web Service wants to implement a "software-software dialogue" between different systems can be called each other, breaking the software application, Web site and various devices in the state of incompatibility between the realization of "web-based seamless integration" goal.
Wsdl
The Web Service Description Language WSDL is a formal description document provided in a machine-readable manner and XML-based language used to describe Web service and its functions, parameters, and return values. Because it is XML-based, WSDL is both machine-readable and human-readable.
Uddi
The purpose of UDDI is to establish standards for e-commerce; UDDI is a web-based, distributed, Web service-provided, information Registry Implementation Standard specification that also includes a set of Web service registrations that enable enterprises to provide themselves. To enable other enterprises to discover the implementation criteria for the Access Protocol. Calling RPC with message delivery
The WEB service itself is actually implementing communication between applications. We now have two methods of application communication: RPC Remote procedure call and message delivery. When using RPC, the concept of a client is to invoke a remote procedure on the server, typically by instantiating a remote object and calling its methods and properties. The RPC system attempts to achieve a position of transparency: the server exposes the interface of the remote object, and the client is like the interface of these objects that are used locally, so that the underlying information is hidden, and the client does not need to know which machine the object is on.
How do I publish a WebService?
1, with Jdk1.6.0_21 later release a WebService service. and view its WSDL document through the address bar.
2. Generate the client code through Wsimport, invoke and view the results of the run. (Learning how to call is our focus).
It should be noted that jdk1.6._07 after the release of the JDK version WebService must be fully annotated code, if you are using a jdk1.6.0_21 later version, because it already contains ws2.1 so, you can only add @webservice annotations to the class .
Here are two different pieces of code:
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 RPC-enabled message style
public class HelloWorld {
Following through the @webmethod annotations, the external public method
@WebMethod
Public String SayHello () {
return "HelloWorld";
}
public static void Main (string[] args) {
Endpoint.publish ("Http://localhost:9999/helloworld", newHelloWorld ());
}
}
2: The following is the WebService code published on jdk1.6.0_24:
Package com.itcast;
Import Javax.jws.WebService;
Import Javax.xml.ws.Endpoint;
@WebService//Note this annotation is required only for this annotation, and the default SOAP message style is: DOCUMENT
public class HelloWorld {
Public String SayHello () {
return "HelloWorld";
}
public static void Main (string[] args) {
Endpoint.publish ("Http://localhost:9999/helloworld", newHelloWorld ());
}
}
First WebService Service
Package com.itcast;
Import Javax.jws.WebService;
Import Javax.xml.ws.Endpoint;
/**
* First WebService Service Application
*/
By annotations, this type of publication is indicated as a webservice
@WebService
public class HelloWorld {
Public String SayHello () {
Return "Hello World";
}
In the main method, use the Javax.xml.ws.Endpoint endpoint to publish an app
public static void Main (string[] args) {
Endpoint.publish ("Http://127.0.0.1:9999/helloworld",
New HelloWorld ());
}
}
Code Description: All non-static public methods of the HelloWorld class will be exposed externally.
Wsimport Tool Description:
? Wsimport is a JDK-brought tool that generates client-side calling code based on a WSDL document. Of course, the Java code will be generated on the client, regardless of what language the server-side webservice is written in. It doesn't matter what the server is written about.
? 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 >-A. java file will be generated.
-p< generated new package name >-The generated class is placed under the specified package.
(Wsdlurl)-HTTP://SERVER:PORT/SERVICE?WSDL, Required parameters
Use:
1: You can check your current version number by Java–version. If the version is too low, you can install a higher version of the JDK.
Or simply copy the JDK directory that someone else has installed to your machine, such as the D:\jdk1.6.0_24 directory.
Because the previous environment variable has been set to the previous version of the JDK directory, namely java_home and path two environment variables.
You can reset the environment variable to: Java_home=d:\jdk1.6.0_24,path=%java_home%\bin,
After you reset the environment variables, you reopen a doc (command line) window. It only takes effect.
If you do not want to modify an environment variable that you have already configured, you can enter the following command in the Command Line window to make jdk1.6.0_24 effective:
Set path = d:\jdk1.6.0_24\bin;%path% (Enter)
See if the JDK version number has changed by Java–version.
2: Go to a relatively clean directory, I set up a new directory on the D disk named: 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 source code files, later. (dot) refers to placing the code on the current account.
The last http .... refers to the address where the WSDL specification is obtained.
5: The. java file and the. class file are generated at this time. (both contain the original package name). Copy the code into your project. (Copy only Java files)
6: In the new project, a new class, (can be located under any package), the code generated above the call, see the next page ppt.
7:wsimport Other parameter descriptions, we often use parameters of-d,-s,-p
-d< directory > will generate a. class file.
Example: Wsimport–d.http://127.0.0.1:9999/helloworld?wsdl
-s< directory > will generate a. java file.
Example: Wsimport–s.http://127.0.0.1:9999/helloworld?wsdl
-p< Package name > change the generated file (. java or. class to the specified package name)
Example: Wsimport-s. -P Com.beijing.itcasthttp://127.0.0.1:9999/helloworld?wsdl
For the-p parameter, note the modification of the package name, which puts the generated classes under the package specified by-p. Presentation
It is necessary to note that when you use the-p parameter only, it will be compiled into a. class file using-D as well. –d parameter write or not write, it is there, do not abandon.
The source code for Runmain.java is as follows:
Package com.leaf;
Import Com.itcast.HelloWorld;
Import Com.itcast.HelloWorldService;
/**
* Call the remote code by calling the generated class
*/
public class Runmain {
public static void Main (string[] args) {
Returning the calling interface from the Gethelloworldport method of the Helloworldserice
HelloWorld HelloWorld =
New HelloWorldService (). Gethelloworldport ();
String str = Helloworld.sayhello (); Execute call
System.err.println (str);//Return HelloWorld string
}
}
The difference between WebService and ordinary Web programs
1, WebService only uses the HTTP POST method transmits the data, does not use the Get method;
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 from the data transmission format is limited. The data used by WebService is based on XML format. The current standard webservice mainly uses the SOAP protocol in the data format. The SOAP protocol is actually a text protocol based on XML encoding specification.

WebService and Web server differences:
We can think of webservice as an application on a Web server, and conversely, a Web server is a necessary container for the WebService runtime. This is their difference and connection.

Features of WebService:
1, webservice through the HTTP POST way to accept customer requests
2, WebService and clients generally use the SOAP protocol to transfer XML data.
3, it is designed for cross-platform or cross-language.

WebServices (i)

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.