CXF Create WebService application diagram _soa

Source: Internet
Author: User
Tags wsdl
CXF 2.7.13

eclipse:3.5

Official website: http://cxf.apache.org/index.html

The first step is to create the service side

1, create Dynamic Web project, Guide CXF jar Package

2, create the interface and implementation class, the following figure




3, Helloworld.java Code

Package com.lu;

Import Javax.jws.WebMethod;
Import Javax.jws.WebParam;
Import Javax.jws.WebService;
 
@WebService Public
interface HelloWorld {
	
	@WebMethod public
	string SayHello (string name);
}

Helloworldimpl.java Code

Package Com.lu.impl;

Import Javax.jws.WebService;

Import Com.lu.HelloWorld;
@WebService (endpointinterface= "Com.lu.HelloWorld", Servicename= "Helloworldws") Public
class Helloworldimpl Implements HelloWorld {

	@Override public
	string SayHello (string name) {return

		"Hello world,i am cxf!" +name;
	}
public static void Main (String args[]) {
	HelloWorld hw = new Helloworldimpl ();

	String address = "Http://localhost/hello";
	Javax.xml.ws.Endpoint.publish (address, HW);
	System.out.println ("WebService run ...");
	
}


4, if successful, then enter the WSDL address in the browser, get the following interface



The second step is to create a client call

1, create Java project, named "Cxfclient"

2, configure Wsdl2java, if there is a problem, then add CXF package bin to the path path until the following interface appears



3, switch to cxfclient under the SRC path, execute command Wsdl2java http://localhost/hello?wsdl

4, after refreshing the SRC directory, get the following files


5, the new client Invoke class Cxfclient.java, the code is as follows:

Package com.lu;

Import Com.lu.impl.HelloWorldWS;

public class Cxfclient {public
	static void Main (String args[]) {
		Helloworldws hwws = new Helloworldws ();
		HelloWorld HW = Hwws.gethelloworldimplport ();
		System.out.println (Hw.sayhello ("from Apache"));
		
	}


Console output "Hello world,i am cxf!from Apache"








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.