WebService interface Development Simple example

Source: Internet
Author: User
Tags wsdl

Webservice is the external interface of the system, For example, if you want to get resources or information from other websites or servers, others will not share the database with you, he can only give you a method that they have written to get the data, and you can use the interface he provided to be able to write the method to achieve Data Sharing the purpose.

The attachment is an example of using axis to write webservice, and this example webservice provides two methods, namely, SayHello and Sayhellotoperson, the first one simply returns a "Hello" string with no parameters, The second function takes a string as a parameter and returns the "Hello parameter value", which is simple, but clearly illustrates the webservice process from writing code to publishing to webservice and test-writing.

Here is the procedure:

1, Writing Service Code

The service Code provides two functions, namely SayHello and Sayhellotoperson, in the Helloservice.java class

2, Publish WebService

To publish the HelloService class written above as webservice, you need to build a Web application first. The following is an example of using axis to create a WebService service under Tomcat.

3. Create a Web application under Tomcat

In this example, a context path for Test_webservice Web applications was created under Tomcat.

(1) Create the following file system under Tomcat WebApps

Test_webservice

Web-inf

Lib

Classes

(2) Create the Web.xml file under the Web-inf folder, and configure axis primarily in Web.xml.

4, copy axis-related jar files

Copy axis related jar files to the Web-inf\lib folder. These documents include:

Activation.jar
Axis.jar
Axis-ant.jar
Axis-schema.jar
Commons-discovery-0.2.jar
Commons-logging-1.0.4.jar
Jaxrpc.jar
Log4j-1.2.8.jar
Mailapi.jar
Saaj.jar
Wsdl4j-1.5.1.jar
Xmlsec-1.3.0.jar

5. Test published Web Applications

Start Tomcat service, open IE browser, visit http:host:port/test_webservice/services,

If you see the following interface, axis deployment is successful.

6, Publish WebService

Publish WebService need to use the existing adminservice to implement, here I wrote a batch file to publish WebService, later if need to publish other files, only need to modify the corresponding parameters.

(1) Create the DEPLOY.WSDD file.

(2) Create a batch file Deploywebservice.bat that publishes the WebService service.

Where E:\workspace\Libwebservice is the folder that holds the corresponding jar files for axis, all of the jar files are now added to this folder.

The parameter after-L is the corresponding access address for the adminservice of the local webservice to be published.

The last DEPLOY.WSDD is the corresponding configuration file name.

(3) By copying the Deploy.wsdd file and the Deploywebservice.bat file to the same folder, and executing the deploywebservice.bat batch file, you can publish the Java class described in DEPLOY.WSDD as WebService. Visit Http://host:port/test_webservice/services after publishing completes

As can be seen from the above picture, after the successful release, a helloservices service. This means that HelloService has been published successfully.

7, view WSDL for helloservices

Access HTTP://HOST:PORT/TEST_WEBSERVICE/SERVICES/HELLOSERVICES?WSDL can see the contents of the WSDL

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.