Author: Fengsha madfool@163.net
Related download:
Apache soap http://xml.apache.org/soap/index.html
Tomcat4.0.4 http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0.4/
1. Install the Apache SOAP to the root directory of the C: / soap-2_3_1
2. Install Tomcat4.0.4 to C: / Program Files / Apache Tomcat 4.0
3. Copy the C: /SoAP-2_3_1/webapps/soap.war file to the C: / Program Files / Apache Tomcat 4.0 / WebApps directory
4. Establish test catalog C: / SOAPTEST and C: / SOAPTEST / CLASSES
5. Modify the system environment variable ClassPath, add C: /SoAptest/Classes/test.jar
6. Start Tomca4.0.4, there are two: a. Execute C: / Program Files / Apache Tomcat 4.0 / bin / startup.ba; b. Open Apache Tomcat4.0.4 through system management service management
7. Establish a test Java source file, and the source file should be placed under the directory C: / SOAPTEST
//Simplan.javaPackage test; public class simplemath {public double getsinvalue (double infut) {double return = math.sin (input); return ret;}} - second Java source file ------- ---------
IMPORT JAVA.IL. *; Import java.util. *; Import java.util. *; Import org.apache.soap.util.xml. *; Import org.apache.soap. *; Import org.apache.soap.rpc. *; public class simplemathclient {public static void main (string [] args) throws exception {system.err.println ("soap call testing"); double value = math.random (); SimpleMathClient SMC = New SimpleMathClient (); // Call remote SOAP service Double ReturnValue = smc.dorequest (value); system.err.println ("the sin value of" value "is:" returnvalue);} public Double Dorequest (Double Value) Throws Exception {// Build The Call. Call call = new call (); // Set URI Call.SetTarGetObjecturi ("URN: Test.math.sin") of the remote object; // Set the call Method Call.SetMethodName ("getSinvalue"); // Sets the coded style call.setencodingStyleuri (constants.ns_uri_soap_enc); // Setting the parameter of the method calling Vector params = new vector (); params.addelement (new parameter ("input" , Double.Class, NULL); Call.SetParams (params); // Send RPC Request Response Resp = CALL.INVOKE (N EW URL ("http://127.0.0.1:8080/soap/servlet/rpcrouter"), "" "; if (resp.generatedFault ()) {// Remote call error handling Fault Fault = Resp.GetFault (); System.out.println ("The Call Failed:"); System.out.Println ("Fault Code =" Fault.getFaultCode ()); System.out.Println ("Fault String =" Fault.getFaultString () ); RETURN 0.0d;} else {// Call successfully, get return value parameter results (); return () Result.getValue ()). DoubleValue ();}}} 8. Compile JAVA Source File, and package a. CD C: / soaptest b. Javac -d classes * .java c. Cd classes d. Jar -cvf test.jar Test
9. Soap Service Publishing Using IE Browser Http: // Localhost: 8080 / soap / admin / index.html, enter deploy, fill in the following information: ID: URN: Test.math.sin Scope: Request Methods getSinvalue Provider TYPE : Java Java Provider Provider Class: Test.SIMPLEMATH JAVA Provider Static: No Confirming Publish, you can click List to view the published service! 10. Run the test program a. CD C: / soaptest b. Java test.simplemathclien should be able to see the number of returned values, then proof the configuration and test success, you can post your own SOAP service!
Reference book: JavaWeb service application development detailed