Spring Integrated CXF3.1 Implementation WebService

Source: Internet
Author: User
Tags wsdl

First on the service-side code

Import javax.jws.WebService; @WebServicepublic interface HelloWorld {public string addmessage (String user);p ublic void Setmessage (String mess);}

Import Javax.jws.WebService; @WebService (endpointinterface = "Org.server.service.HelloWorld") public class Helloworldserver implements HelloWorld {private string Mess;public string getmess () {return mess;} public void setmess (String mess) {this.mess = mess;} @Overridepublic string AddMessage (string user) {return "Welcome" + user + this.mess;} @Overridepublic void Setmessage (String message) {this.mess = message;}}

<!--CXF Configuration--><servlet><servlet-name>cxfservice</servlet-name>< servlet-class>org.apache.cxf.transport.servlet.cxfservlet</servlet-class></servlet>< servlet-mapping><servlet-name>cxfservice</servlet-name><url-pattern>/service/*</ Url-pattern></servlet-mapping>

How the client Implements
package Org.my.client;import Java.net.malformedurlexception;import Java.net.url;import Javax.xml.namespace.QName;import Javax.xml.ws.service;import Org.easy.java.bean.user;import Org.easy.java.server.service.accountmanager;public Class Accountclientgood {public static void main (string[] args) throws malformedurlexception {URL wsdlurl = new URL ("http: Localhost:8881/globalservice/service/accountmanager?wsdl "); QName service_name = new QName ("http://imp.server.java.easy.org/", "Accountserverservice"); Service service = Service.create (Wsdlurl, service_name); Accountmanager Accountmanager = Service.getport (Accountmanager.class); User User=new User (); User.setusername ("Dsadas"); System.out.println (accountmanager.getuserinfo (user));}} 
package Org.my.client;import Org.apache.cxf.jaxws.jaxwsproxyfactorybean;import Org.easy.java.bean.user;import Org.easy.java.server.service.accountmanager;public class Accountclient {public static void main (string[] args) {   Jaxwsproxyfactorybean factory = new Jaxwsproxyfactorybean (); Factory.setserviceclass (Accountmanager.class); Factory.setaddress ("Http://localhost:8881/globalService/service/AccountManager"); Accountmanager accountmanagera= (Accountmanager) factory.create (); Accountmanagera.printlogin ("Tudou"); System.out.println ("------------"); User User=new user (); User.setusername ("Digua"); User.setcomment (accountmanagera.getuserinfo (user)); System.out.println (User.getcomment ()); }}
Package Org.test.client;import Org.apache.cxf.endpoint.client;import Org.apache.cxf.jaxws.endpoint.dynamic.jaxwsdynamicclientfactory;public class TESTWB {public static void main (String[ ] args) throws Exception  {jaxwsdynamicclientfactory  DCF = Jaxwsdynamicclientfactory.newinstance (); ClassLoader Classloader=thread.currentthread (). Getcontextclassloader (); Client client = dcf.createclient ("http://localhost:8881/globalwb/service/HelloWorld?wsdl", ClassLoader); object[] res = Client.invoke ("AddMessage", "Dasdada"); SYSTEM.OUT.PRINTLN ("Echo response:" + res[0]);}}






Spring Integrated CXF3.1 Implementation 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.