I. Environment Settings:
Environment APACHE-Tomcat-6.0.29 + axis-bin-1_4 (download URL: http://labs.renren.com/apache-mirror/ws/axis/1_4/axis-bin-1_4.zip
).
1. tomcat installation path: directly extract tomcat to path D:/Apache-Tomcat-6.0.29.
2. axis installation path: extract directly to D:/axis-1_4 /.
3. Copy the entire axis folder (D:/axis-1_4/webapps) under webapps of axis to webapps of Tomcat (D:/Apache-Tomcat-6.0.29/webapps ).
4. start Tomcat: Double-click Run D:/Apache-Tomcat-6.0.29/bin/startup
5. Access: http: // localhost: 8080/axis/
2. Release your own service configuration:
Add the following environment variables to my computer-advanced-environment variables:
Axis_home is set to D:/axis-1_4, that is, the place that just unzipped (note the unzipped hierarchy, this directory has lib and so on ..)
Set axis_lib to % axis_home %/lib
Axisclasspath is set to % axis_lib %/axis. jar; % axis_lib %/commons-discovery-0.2.jar; % axis_lib %/commons-logging-1.0.4.jar; % axis_lib %/jaxrpc. jar; % axis_lib %/SAAJ. jar; % axis_lib %/log4j-1.2.8.jar; % axis_lib %/xml-apis.jar; % axis_lib %/xercesimpl. jar (here, jars depend on your download, which is different from install.html in your own document)
Add axisclasspath to classpath (classpath = % axisclasspath % ;.....).
(Xml-apis.jar, xercesimpl. Jar these two jar in my axis-bin-1_4 does not, and separately from the csdn under, do have to be another ?)
3. Simple WebService release:
1. Create a webproject
The compiling class is as follows:
Import java. util .*;
Public class test
{
// Fields
Private string name = "Gaga ";
Private int age = 20;
Private list items = new arraylist ();
// Method at here.
Public String getname ()
{
Return name;
}
Public int getage ()
{
Return age;
}
Public list getitems ()
{
Return items;
}
}
2. Put the compiled test. Class under D:/Apache-Tomcat-6.0.29/webapps/axis and change it to test. JWS. You do not need to restart tomcat.
3. Compile the test client:
Import org. Apache. axis. Client .*;
Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
Import javax. xml. namespace. QNAME;
Public class testwebservice
{
Public static void main (string ARGs [])
{
System. Out. println ("start invoking ....");
Try {
String endpoint =
& Quot; http: // localhost: 8080/axis/test. JWS
";
// The file you wrote
Service = new service ();
Call call = (call)
Service. createcall ();
Call. settargetendpointaddress
(New java.net. URL (endpoint ));
Call. setoperationname ("getage ");
// Enter the name of the method you want to call
Int ret = integer. parseint
("" + Call. Invoke (new object [] {});
System. Out. println (RET );
} Catch (exception e ){
System. Err. println (E. tostring ());
}
System. Out. println ("finished the invoking .");
}
}
Run main in eclipse. The eclipse console displays:
Start invoking... 20
Finished the invoking.
4. More complex WebService release (axis)
Take the local machine as an example: myeclipse5.5 to create a web project.
1. Import the project as follows jar:
-
Axis. Jar
-
Jaxrpc. Jar
-
SAAJ. Jar
-
Commons-logging.jar
-
Commons-discovery.jar
-
Wsdl4j. Jar
1. Create a class com. cattsoft. Service. interfaceservice.
2. Generate. WSDL through Java class
Right-click the Java class (interfaceservice. Java) that needs to be published as WebService-> running mode-> running
Under the main type, select: Search for the main class, including the Library, search for the main class, and then search
Select org. Apache. axis. WSDL. java2wsdl. Note: axis. jar must be referenced in the project.
-O webroot/WSDL/interfaceservice. WSDL
-L http: /localhost: 8080/axis/services/interfaceservice
-N "urn: SPs"
Com. cattsoft. Service. interfaceservice
Note:
-O specifies the name of the generated WSDL file.
-L specifies the Service Location
-N target namespace of the WSDL File
Run
After completing the preceding steps, the XXX. WSDL file will be generated.
3. Generate WebService-related Java classes through the. WSDL File
Right-click the XXX. WSDL file generated above-> running mode-> running
Under the main type, select: Search for the main class, including the Library, search for the main class, and then search
Choose org. Apache. axis. WSDL. wsdl2java.
Note: The axis. jar package must be referenced in the project.
Independent variable:
-O./src/
-D session
-S true
Web/WSDL/im4crmservice. WSDL
-P com. cattsoft. Im. Service. WebService. Client
Note:
-O: directory of the output file (.-indicates the current directory)
-S: Generate server binding code
-D release Scope
-S: whether to generate deploy. WSDD and undeploy. WSDD files for publishing and revoking WebService. True indicates generating a publishing file.
-N urn: namespace package name
-P: generate the Java class package name
Xxx. WSDL file name.
Run
After completing the preceding steps, the relevant Java classes (interfaceservice_porttype.java, interfaceserviceservice. Java, interfaceserviceservicelocator. Java,
Interfaceservicesoapbindingimpl. Java, interfaceservicesoapbindingskeleton. Java,
Interfaceservicesoapbindingskeleton. Java), deploy. WSDD, undeploy. WSDD file.
4. Put all the classes of D:/workspace/m2mwebproj/webroot/WEB-INF/classes under D:/Apache-Tomcat-6.0.29/webapps/axis/WEB-INF/classes.
5. Deploy WebService to Tomcat:
After starting tomcat, run CMD and the command window appears. Run the following command:
D:/Apache-Tomcat-6.0.29/webapps/axis/WEB-INF/classes> JAVA-CP % axisclasspath % Org. apache. axis. client. adminclient COM/cattsoft/service/client/deploy. WSDD
The command window is displayed as follows:
Processing file COM/cattsoft/service/client/deploy. WSDD
<Admin> done processing </admin>
And D:/Apache-Tomcat-6.0.29/webapps/axis/WEB-INF directory to generate a file server-config.wsdd.
6. Enter URL: http: // localhost: 8080/axis/in the browser/
Click list to view the published WebService.
Note: You need to modify the generated files before using them.
Modify the file D:/Apache-Tomcat-5th/webapps/axis/WEB-INF/classes/COM/cattsoft/service/client/deploy. WSDD before publishing the service (step 1)
The original value is "com. cattsoft. Service. Client. interfaceservicesoapbindingskeleton
Change to <parameter name = "classname" value = "com. cattsoft. Service. interfaceservice
"/>
The post-release file D:/Apache-Tomcat-6.0.29/webapps/axis/WEB-INF/server-config.wsdd also needs to be modified.
Change to: <service name = "interfaceservice" provider = "Java: RPC">
<Parameter name = "allowedmethods" value = "*"/>
<Parameter name = "typemappingversion" value = "1.2"/>
<Parameter name = "wsdlporttype" value = "interfaceservice"/>
<Parameter name = "Scope" value = "session"/>
<Parameter name = "classname" value = "com. cattsoft. Service. interfaceservice"/>
<Parameter name = "wsdlserviceport" value = "interfaceservice"/>
<Parameter name = "wsdltargetnamespace" value = "urn: SPs"/>
<Parameter name = "wsdlserviceelement" value = "interfaceserviceservice"/>
</Service>
V. Testing
Compile the test class in the webproject project:
Package com. cattsoft. Service. test;
Import com. cattsoft. Service. Client. interfaceserviceservice;
Import com. cattsoft. Service. Client. interfaceserviceservicelocator;
Import com. cattsoft. Service. Client. interfaceservice_porttype;
Public class test {
Public static void main (string [] ARGs ){
Try {
Interfaceserviceservice service = new interfaceserviceservicelocator ();
Interfaceservice_porttype client = NULL;
System. Out. println ("url:" + service. getinterfaceserviceaddress
());
Client = service. getinterfaceservice ();
String retvalue = client. callm2m ("","");
System. Out. println ("retvalue:" + retvalue );
} Catch (exception e ){
System. Err. println ("execution failed. Exception:" + E );
}
}
}
Run, OK.