Axis WebService development (1)

Source: Internet
Author: User

1. Configure the development environment

1. the development environment is jdk1.6, tomcat6.0, and myeclipse8.5.

2, first download axis1.4, you can download in http://xml.apache.org.

3, download the axis compressed package decompress % axis_home % lib directory jar package, put in the project/WEB-INF/lib directory, my project name is WebService

4. Axis supports the deployment and development of three web services:

(1) dynamic invocation interface (DiI)

(2) Dynamic proxy method

(3) stubs Mode

Here, we will only introduce the stubs method, which is usually used at work.

Ii. Code Development

1. Add the following content to the project's web. xml file:

<Servlet>
<Servlet-Name> axisservlet </servlet-Name>
<Servlet-class> org. Apache. axis. Transport. http. axisservlet </servlet-class>
</Servlet>
 
<Servlet-mapping>
<Servlet-Name> axisservlet </servlet-Name>
<URL-pattern>/servlet/axisservlet </url-pattern>
</Servlet-mapping>

<Servlet-mapping>
<Servlet-Name> axisservlet </servlet-Name>
<URL-pattern> *. JWS </url-pattern>
</Servlet-mapping>

<Servlet-mapping>
<Servlet-Name> axisservlet </servlet-Name>
<URL-pattern>/services/* </url-pattern>
</Servlet-mapping>

2. server program: Service. Java

// Here we will first introduce that the parameter passing is the string type provided in Java, and later we will introduce that the parameter passing is of the custom object type.

Package com. WebService. Service;

Public class service {

Public Service (){}

Public String dorequest3 (string Str ){
Return Str. touppercase ();
}

}

3. In the project's WEB-INF directory, create deploy. WSDD with the following content:

<Deployment xmlns = "http://xml.apache.org/axis/wsdd/" xmlns: Java = "http://xml.apache.org/axis/wsdd/providers/java">

<Service name = "checkorder" provider = "Java: RPC">
<Parameter name = "classname" value = "com. WebService. Service. Service"/>
<Parameter name = "allowedmethods" value = "dorequest3"/>
</Service>
</Deployment>
The value of <parameter name = "allowedmethods" value = "dorequest3"/> is the interface accessed by the service. This method is public. If multiple methods are used ", "separated. If you want all public methods in the service to be external, you can write them as: value = "*".

4. Create deploy. bat under the WEB-INF directory of the project (my project name is WebService) with the following content:

Set axis_lib = F: \ jspproject \ WebService \ WEB-INF \ Lib
Set java_cmd = Java-djava. Ext. dirs = % axis_lib %
Set axis_servlet = http: // localhost: 8000/WebService/services
% Java_cmd % org. Apache. axis. Client. adminclient-l % axis_servlet % deploy. WSDD

Execute this batch file to generate the server-config.wsdd.

5. Release the project to Tomcat, start Tomat, enter the command line, switch to the directory of deploy. bat, my is F: \ jspproject \ WebService \ webroot \ WEB-INF

Run deploy. bat. After successful execution, the following message is displayed:

Processing file deploy. WSDD

<Admin> done processing </admin>

At this point, you have an additional WEB-INF under % atat_home % webapps \ WebService \ server-config.wsdd.

6. Generate a client and test the program.

Create the wsdl2java. BAT file under the project's WEB-INF directory with the following content:

Set axis_lib = F: \ jspproject \ WebService \ WEB-INF \ Lib
Set java_cmd = Java-djava. Ext. dirs = % axis_lib %
Set output_path = F: \ jspproject \ WebService \ SRC
Set package = com. WebService. Client
% Java_cmd % org. Apache. axis. WSDL. wsdl2java-o % output_path %-P % package % http: // localhost: 8000/WebService/services/checkorder? WSDL

Output_path is the package path of the client program,

Keep Tomcat started, and switch the command line to wsdl2java. in the bat directory, run wsdl2java. bat. After the execution, refresh the SRC of the project and you will find that the package COM. webService. client with checkordersoapbindingstub. java, service. java, serviceservice. java, serviceservicelocator. java.

Now you can test WebService. The program is as follows:

Package com. WebService. test;

Import java. RMI. RemoteException;

Import javax. xml. rpc. serviceexception;

Import org. JUnit. test;

Import com. WebService. Client. serviceservice;
Import com. WebService. Client. serviceservicelocator;
Import com. WebService. Client. Service;

Public class webservicetest {

@ Test

Public void test3 () throws serviceexception, RemoteException {

Serviceservice = new serviceservicelocator ();

Service = serviceservice. getcheckorder ();

String STR = service. dorequest3 ("lam ");

System. Out. println (STR );

}

}

After execution, the following error occurs: Lam.

Okay, the simple WebService is successful.

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.