A simple HelloWorld example based on the CFX WebService

Source: Internet
Author: User
Package test;

Import Javax.jws.WebService;

@WebService Public
interface HelloWorld {public

	string SayHello (string name);
}
Package test;

Import Javax.jws.WebService;

@WebService public
class Helloworldimpl implements HelloWorld {public

	string SayHello (string name) {
		System.out.println ("SayHello is called");
		Return "Hello" +name;
	}

}
Package test;

Import Org.apache.cxf.endpoint.Server;
Import Org.apache.cxf.jaxws.JaxWsServerFactoryBean;

public class Mainserver {public

	
	static void Main (string[] args) {
		
		Jaxwsserverfactorybean Factorybean = new Jaxw Sserverfactorybean ();
		HelloWorld Hello = new Helloworldimpl ();
		Factorybean.setservicebean (hello);
		Factorybean.setserviceclass (helloworldimpl.class);
		Factorybean.setaddress ("Http://127.0.0.1:8080/HelloWorld");
		
		Server server = Factorybean.create ();
		Server.start ();
	}

}


Package test;

Import Org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class Helloworldclient {public

	
	static void Main (string[] args) {

		Jaxwsproxyfactorybean bean = new Jaxwspro Xyfactorybean ();
		Bean.setaddress ("Http://127.0.0.1:8080/HelloWorld");
		Bean.setserviceclass (helloworld.class);
		
		HelloWorld world = (HelloWorld) bean.create ();
		System.out.println (World.sayhello ("LCY"));
	}

}

Note: Some of the online video examples give the Mainserver class inside only wrote Factorybean.setserviceclass (Helloworldimpl.class);

Should have been added to the front.

HelloWorld Hello = new Helloworldimpl ();

Factorybean.setservicebean (hello);

Otherwise it will be reported abnormal, abnormal situation see: http://topic.csdn.net/u/20110809/15/a39454e4-4c73-4ef6-9a34-5b30608eed4f.html?62533

Solve the problem from: http://www.opensourceforce.org/forum/viewthread.php?action=printable&tid=2613

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.