Two days before two days wrote two blogs develop Java Web services - Axis development plan, in-depth exploration SOAP1.1 - use saaj1.2.1, some readers may complain about Java's Web service development, what is so complicated? It's better to knock a few keys under the NET platform, :) To discuss, a high-level Web service implementation scheme is based on JAX-RPC service implementation. The JAX-RPC 1.1 specification does not define any APIs for implementing JAX-RPC-based services. JAX-RPC-based services can use Java classes or use WSDL document implementations, both of them, JAX-RPCs do not have any requirements for their server to access and use deployment services. JAX-RPC-based service is extremely similar to the development of RMI applications (JAX-RPC is a web service that uses SOAP-based RPC and WSDL mechanisms to call the heterologous environment, integrating the performance of remote process calls (RPC), by providing Java The map required between XML / WSDL encapsulates the complex operation of the underlying SOAP packaging and message exchange). 1. Develop JAX-RPC services based on Java class.
Steps are basically similar to RMI development: 1) Define remote interface (service definition); 2) Implementation remote interface (service implementation scheme); 3) Configure service; 4) Generate a deployment file; I implemented: 1. Define remote interface (StudentInfoif.java): / ** * StudentInfoif.java * Copyright 2005-2-10 * @ Author A Fei * / package edu.cun.jws.jaxrpc; import java.rmi.remote; import java.rmi.RemoteException; / ** * This interface is primarily used for JAX-RPC service definition (remote interface) * / public interface studentinfoif extends Remote {/ ** * @ param studentname This is a string of student name * @ Return String Returns the information of students * / public String getStudentInfo (String studentName) throws RemoteException;} 2, remote interfaces (StudentInfoImpl.java): / ** * StudentInfoImpl.java * Copyright 2005-2-10 * @ author punk * / package edu.cun.jws. jaxrpc; import java.rmi.Remote; import java.rmi.RemoteException; / ** * remote Interface StudentInfoIF, service implementation * @ see StudentInfoIF * / public class StudentInfoImpl implements StudentInfoIF {public String getStudentInfo (String studentName) {System. Out.println ("Your name:" studentname); Return New String ("Hello");}} Compiles the above source file: java * .java -d. Finally, you can get an EDU folder in the current folder. It is the byte class of our needs. 3. Preparing for deployment is due to the use of JWSDP1.5 development tools, readers please go to the Sun website to download the JWSDP development tool http://java.sun.com/webservices/downloads/webservicesPack.html: We use JWSDP installation path / JAXRPC The tool WSDeploy in / bin, this tool first completed compilation by calling wscompile -gen: server (because the object we deployed now is Tomcat, so we want to call WSDeploy, if it is the container of the standard J2EE implementation, use WSCompile to play , Please see the help documentation): Because it is WSDeploy, you must write a jaxrpc-ri.xml file, for our example: <------------ This is you Space named by yourself TypenamespaceBase = "http://www.cun.edu.cn/jws/types" <------------ is also your defined urlpatternbase = "/ studentInfo">
<---------- This is the interface IMPLEMentation = "edu.cun.jws.jaxrpc.studentinfoImpl" /> <----------- Implement the interface < ----------- is equal to URL-Pattern in the web.xml file
If you need to populate the web.xml file in advance:
60
Preparing for deployment. 4, deploy (to be familiar with J2EE deployment specification, here my deployment object is Tomcat) We create a folder StudentInfo The following is a folder content / studentInfo / web-inf / class <------- put our service Copy here, here is an EDU folder / lib <------- must-package, web.xml <------- We write file jaxrpc-ri.xml <----- - The file written in the previous step Note that this must have a JAX-RPC-related package, as well as Saaj-related packages (JavaMail, Jaf, JAXP), I have used the following packages here (because JDK1.5, So JAXP related package is not included): activation.jar (jaf), jaxrpc-api.jar, jaxrpc-impl.jar, jaxrpc-spi.jar, mail.jar, saaj-api.jar, saaj-impl.jar; After that, we packaged into a WAR file (because the input file required by WSDeploy is a WAR archive file): Convert to the STUDENTINFO directory, set the running path running WSDeploy, run: Jar CVF StudentInfo.war * WSDeploy -o StudentInfoApp . War StudentInfo.war finally we got a StudentInfoApp.war file, which is a program we need to deploy a web service. We copy it to Tomcat's WebApps directory, automatically deploy 5, test in the browser: http: // localhost: 8080 / studentInfoApp / info test success, web service deployment, client test, yourself Write, you can use Java, you can also use the NET platform, etc. as a client, please refer to my example: Develop a Java Web service -Axis development plan using the SOAP, is the call client using the C # as the service. PS: WEB service development based on JAX-RPC is so simple, many internal conversion content has been completed, we can concentrate on business logic, welcome to join Java Web Service development ranks. Readers who have any questions about this article can leave a message to me, or send a problem to my e-mail: gdanthrowwy@126.com