Foreword
What is the core of the AXIS project in its core, the AXIS project is the engine of the third generation Simple Object Access Protocol (SOAP). At the highest level, it is a perfect framework for creating and deploying XML transactions with SOAP. The AXIS project is an open source based on SOAP V1.1 Java executive specification. What is SOAP in accordance with W3C, "SOAP is a exchanging organization that is deliberately used in a dispersed, distributed environment." In other words, SOAP is related to communication with XML, and is related to communication in different network protocols. It is a telegraph protocol that acts as a leverage, using HTTP as its transport layer, and performs a remote method as its data layer, is a well-known SOAP / Web service. In history, SOAP is introduced by Microsoft, IBM, and several other companies. The current specification is SOAP V1.1. However, W3C has released a draft of SOAP 1.2, which makes 1.1 norms very confused some places mysterious. AXIS implements four ways to call SOAP services provided in the SOAP execution specification: • Remote Procedure Call (RPC) • Document • Wrapped • Message
Remote Process Call (RPC) Service RPC method is a synchronization technology that performs remote SOAP services in C / S mode. This mode is defined by the following: 1. The client application creates an XML document, including the URI of the server that provides the request service, the method name executed on the server, and the parameters associated with the method. 2. Target service accepts and expands the XML document, and then performs the specified method. 3. When the specified method is executed, Axis maps them to a client response XML document and then sent back to the client. 4. The client receives this response and expands the response result that contains the called method. Documents and packaging service documents and packaging services are very similar, so put it together. The two are different from the RPC service that is neither SOAP-STYLE to bind their data performance layers, and their associated data is not in the RPC service of a simple XML Schema data. Documents and packaging services are only different from each other in their actual implementation, and the documentation has a documentation with the following Schema:
Creating an execution service A SOAP service should be used by any Java classes exposed public methods. These classes don't need to know any cases about SOAP, and even it is performed as a SOAP service. The only limit is that the parameters of its method must be serialized. For example, create a web service that will play a more boring inventory management person. This will include three classes: The first is the Web Service yourself (Listing 1); second, the third is to include business logic (Listing 2 and Listing 3) that supports this service (Listing 2 and Listing 3). Import ch02.inventoryit; / ** * @Desc in stock service * @Author chikai * @Link chikai * @version $ inventoryservice.java 2004- 12-7 11:49:30 $ * @version $ Project webservice * / public class InventoryService {public int addInventory (String sku, int quantity) {InventoryItem item = new InventoryItem (sku, quantity); System.out.println (item );. return (ch02.Inventory.addInventory (item)) getQuantity ();} public int reduceInventory (String sku, int quantity) {InventoryItem item = new InventoryItem (sku, quantity); System.out.println (item); . return (ch02.Inventory.reduceInventory (item)) getQuantity ();} public int getInventoryQuantity (String sku) {InventoryItem item = ch02.Inventory.getInventoryItem (sku); return item.getQuantity ();}} Listing 1: InventoryService .java - Inventory Services This inventory service is a simple Java class containing three public methods: addressory (), reduuceinventory (), and getInventoryquantity (). Each method will accept the simple Java type of the signature method they associated. The following list 2 shows the inventoryItem: package ch02; import java.io.serializable; import java.io.serializable;
/ ** * @Desc inventoryItem bean * @Author chikai * @Link chikai * @version $ inventoryitem.java 2004-12-7 11:50: 24 $ * @version $ Project webservice * / public class InventoryItem implements Serializable {public String sku = null; public int quantity = 0; public InventoryItem () {} public InventoryItem (String sku, int quantity) {this.sku = sku; this.quantity = quantity;} public String getSku () {return sku;} public void setSku (String sku) {this.sku = sku;} public int getQuantity () {return quantity;} public void setQuantity (int quantity) { THIS.QUANTITITY = Quantity;} public string toString () {RETURN ("SKU =" SKU "Quantity =" quantity);}} Listing 2: InventoryItem.java-inventoryItem bean This is a simple bean describing a inventory . Note: Why does INVENTORYITEM do not directly pass Integers and String? The answer is that AXIS requires additional configuration to pass non-original objects. The third class is big and complicated, but it is not annoying. It actually encapsulates our web service to the business logic. Package ch02; import java.util.hashtable;
/ ** * @Desc in stock business logic realizes * @Author chikai * @Link chikai * @version $ inventory.java 2004-12-7 11: 51:23 $ * @version $ Project webservice * / public class Inventory {private static Hashtable inventory = new Hashtable (); public static InventoryItem addInventory (InventoryItem item) {System.out.println ( "ADDING:" item); if (inventory.containsKey (item.getSku ())) {InventoryItem currentItem = (InventoryItem) inventory.get (item.getSku ()); currentItem.setQuantity (currentItem.getQuantity () item.getQuantity ());} else { inventory.put (item.getSku (), item);} return (InventoryItem) inventory.get (item.getSku ());} public static InventoryItem reduceInventory (InventoryItem item) {InventoryItem currentItem = null; if (inventory.containsKey ( Item.getsku ())) {currentItem = (inventoryit) inventory.get (item.getsku ()); CURR entItem.setQuantity (currentItem.getQuantity () - item.getQuantity ());} else {// this is an error and will be handled in Chapter 5} return currentItem;} public static InventoryItem getInventoryItem (String sku) {InventoryItem item = NULL; IF (Inventory.Containskey (SKU)) {item = (inventoryItem) inventory.get (SKU);} else {// this is an error and will be discussed in chapter 5} returnid;}} list 3: Inventory .java - Inventory business logic implementation WEB Service This section describes the Web Service deployment process - a warning, you will see an AXIS deployment descriptor, but it is useless.
The deployment method of the AXIS standard is to use some well-known things, deploy descriptors like Web Service, or WSDD files, although this sounds a bit complicated, it is actually a very simple XML file, used to describe our web service and some Associated attributes, this has a simple example that can be used to deploy Web Service:
Import org.call; import org.apache.axis.client.service; import org.apache.axis.encoding.xmltype; import javax.xml.rpc.parameterMode; / ** * @Desc in stock customer End (test) * @Author chikai * @Link chikai * @version $ inventoryclient.java 2004-12-7 13:49:08 $ * @ version $ Project webservice * / public class InventoryClient {public Integer addInventory (String endpoint) throws Exception {String method = "addInventory"; String sku = new String ( "SKU456"); Integer quantity = new Integer (8); Service service = New service (); call call = (call) service.createcall (); call.settargetendpointaddress (new java.net.URL (endpoint)); call.SetopectionName (Method); call.addparameter ("SKU", XMLType.xsd_string ParameterMode.in; call.addparameter ("Quantity", XMLTYPE.XSD_INT, ParameterMode.in); call.setReturntype (xmltype.xsd_int); Object parameters [] = new ob ject [] {sku, quantity}; return (Integer) call.invoke (parameters);} public Integer reduceInventory (String endpoint) throws Exception {String method = "reduceInventory"; String sku = new String ( "SKU456"); Integer Quantity = new integer (2); service service = new service (); call call = (call) service.createCall (); call.settargetendpointaddress (new java.net.URL (endpoint); call.setoperationname (Method); Call.addparameter ("SKU", XMLTYPE.XSD_STRING, ParameterMode.in; Call.Addparameter ("
quantity ", XMLType.XSD_INT, ParameterMode.IN); call.setReturnType (XMLType.XSD_INT); Object parameters [] = new Object [] {sku, quantity}; return (Integer) call.invoke (parameters);} public Integer getInventoryQuantity (String endpoint) throws Exception {String method = "getInventoryQuantity"; String sku = new String ( "SKU456"); Service service = new Service (); Call call = (Call) service.createCall (); call.setTargetEndpointAddress ( new java.net.URL (endpoint)); call.setOperationName (method); call.addParameter ( "sku", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType (XMLType.XSD_INT); Object parameters [] = new Object [] {sku}; return (Integer) call.invoke (parameters);} public static void main (String [] args) throws Exception {String endpoint = "http: // localhost: 8080 / axis / ch02 / InventoryService. InventoryClient Client = New IN ventoryClient (); Integer ret = client.addInventory (endpoint); System.out.println ( "Adding Got result:" ret); ret = client.reduceInventory (endpoint); System.out.println ( "Removing Got result: " RET); ret= client.getinventoryquantity (endpoint); system.out.println (" getting got results 4: inventoryclient.java) InventoryClient.java-inventory client When the Axis web application receives an extension When the name .jws's file request, it will be approved that this is a special extension because we have mapped the corresponding request to the Axisservlet in the web.xml file, which is handled.
Look at the Web.xml file below: XML Version = "1.0"?>
The first attribute is the address of the target web service. This method is passed to this method is a string: http: // localhost: 8080 / axis / inventoryService.jws. Call.SetTargetendPointdaddress (new java.net.URL (endpoint)); or call.settargetendpointaddress ("http: // localhost: 9080 / axis / helloworld.jws"); the next property is the method name that will be called: AddIndory . Call.SetoperationName (Method); The code of the lower part is a bit possible: Call.AddParameter ("SKU", XMLType.xsd_string, parametermode.in); Call.AddParameter ("Quantity", XMLTYPE.XSD_INT, ParameterMode.in); In a hurry, it seems to be the parameter name and value we will add by the Web Service. In fact, we are telling Axis two parameters, SKU and Quantity. The types of their respective values will be String and Integer. The true parameter value that is bound to this is actually not set, and wait until the call.invoke () method is called. The last attribute is to set the desired type of result to return, in this example is Integer. Call.setRetURNTYPE (XMLTYPE.XSD_INT); now, all properties have been set, it is time to call our web service. Just as previously discussed, AXIS has been told to expect, but in fact, there is no parameter value to be passed to the Call instance. In order to do this, add all parameters to an array object, then pass this array object to the Call.Invoke () method, just like: Object parameters [] = new object [] {SKU, Quantity} Return (Integer); when this method is called, it will call the Web Service Inventory's addressory () method and pass the two values of SKU and Quantity. When the call is completed, it will return an addINventory () operation result for the value of the Integer type. At this point, it is time to enjoy the results. Typing the following connection address at the client browser: http: // localhost: 8080 / axis / ch02 / inventoryservice.jws? WSDL, we will see the same as the picture below: http://blog.9cbs. Net / images / blog_9cbs_net / chikai / 76624 / r_ws.gif compiles and executes InventoryClient, if everything goes well, we will see the following print information: adding got Result: 8removing Got Result: 6Getting Got Result: 6