WebService learning--using eclipse to generate JAX-WS WebService clients

Source: Internet
Author: User
Tags wsdl
The previous article describes how to build a Jax-ws WebService server with Eclipse, and now describes how to build a client

1. Create a Web project, Dynamic Web project (file->new->dynamic Web project) named "Ws-client"


2, create the WebService client (select the client created to right-click New->other->web Services->web Service Client) and enter the address of the WSDL file in the service definition , and choose a running environment in configuration, my environment is Tomcat7.0 and CXF, and then click Next and Finish.


Eclipse background starts generating files and prints logs

Loading frontend jaxws
... Loading DataBinding JAXB ...
wsdl2java-client-d E:\workspace\ws-client\.cxftmp/src-classdir E:\workspace\ws-client\build\classes-p http:// Impl.service.demo.ws/=ws.demo.service.impl-impl-validate-exsh False-dns true-dex true-wsdllocation http:// Localhost:8081/ws-server/services/addserviceimplport?wsdl-verbose-defaultvalues-fe jaxws-db JAXB-WV 1.1 http:// LOCALHOST:8081/WS-SERVER/SERVICES/ADDSERVICEIMPLPORT?WSDL
Wsdl2java-apache CXF 3.1.6

Project structure after file generation:


3. Write main function

Package main;

Import Ws.demo.service.AddService;
Import Ws.demo.service.impl.AddServiceImplService;

public class Main {public

	static void Main (string[] args) {
		Addserviceimplservice service = new Addserviceimplser Vice ();
		AddService port = Service.getaddserviceimplport ();
		int result = Port.add (3, 4);
		
		SYSTEM.OUT.PRINTLN (result);
	}


Run the program, output:

June 14, 2016 5:09:15 pm Org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildservicefromwsdl
Information : Creating Service {Http://impl.service.demo.ws/}addserviceimplservice from wsdl:http://localhost:8081/ws-server/ SERVICES/ADDSERVICEIMPLPORT?WSDL
7

7 is the result of the last call to the server run via WebService.



Related Article

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.