WebService CXF Learning (Getting Started 2): helloworld example

Source: Internet
Author: User

Theory with practice, only talk about theory that became an armchair, with a HelloWorld demo can be more intuitive. Let's start with the explanation below:
First to the Apache official Web download apache-cxf-2.2.2, (now has a higher version 2.4) address: http://cxf.apache.org/
Create a new Java Project, import cxf common. Jar packages, CXF common jar packages are as follows:

1, Commons-logging-1.1.1.jar
2, Cxf-2.4.1.jar
3, Geronimo-activation_1.1_spec-1.1.jar
4, Geronimo-annotation_1.0_spec-1.1.1.jar
5, Geronimo-javamail_1.4_spec-1.7.1.jar
6, Geronimo-jaxws_2.2_spec-1.0.jar
7, Geronimo-servlet_3.0_spec-1.0.jar
8, Geronimo-stax-api_1.0_spec-1.0.1.jar
9, Geronimo-ws-metadata_2.0_spec-1.1.3.jar
10, Jettison-1.3.jar
11, Jetty-continuation-7.4.2.v20110526.jar
12, Jetty-http-7.4.2.v20110526.jar
13, Jetty-io-7.4.2.v20110526.jar
14, Jetty-server-7.4.2.v20110526.jar
15, Jetty-util-7.4.2.v20110526.jar
16, Neethi-3.0.0.jar
17, Saaj-api-1.3.jar
18, Saaj-impl-1.3.2.jar
19, Serializer-2.7.1.jar
CXF the jar package needed to combine spring
(
Spring-asm-3.0.5.release.jar
Spring-beans-3.0.5.release.jar
Spring-context-3.0.5.release.jar
Spring-core-3.0.5.release.jar
Spring-expression-3.0.5.release.jar
Spring-aop-3.0.5.release.jar
Spring-web-3.0.5.release.jar
)
20, Wsdl4j-1.6.2.jar
21, Xalan-2.7.1.jar
22, Xercesimpl.jar
23, Xml-resolver-1.2.jar
24, Xmlschema-core-2.0.jar
25, Jaxb-api-2.2.1.jar----webservices service end needs to add
26. Jaxb-impl-2.2.1.1.jar----If the version in the JDK is consistent with that version, neither the WebServices server nor the client will need to add
(Note: Conflicts between JAXB-API and Jaxb-impl packages and JDK (JDK version <2.0> low), you can overwrite the version 2.2 version of the JDK when using these two jar packs)
How to override the JDK version: Locate the Jre\lib\endorsed folder under the installation directory of the JDK (if the endorsed folder does not exist, create new ones) and place jaxb-api-2.2.1 and jaxb-impl-2.2.1.1 under this folder.

First step: Create a new WebService server interface and implementation class

1, server interface [Java] view plain copy package com.ws.services;      Import Javax.jws.WebService;          @WebService public interface Ihelloservices {public String sayhellotoall (string[] userNames);              Public string[] Gethellowords ();   public string SayHello (string name); }

2, service-side interface implementation class[Java]  View plain copy package com.ws.services.impl;      import javax.jws.webservice;       import com.ws.services.ihelloservices;      @WebService ( Endpointinterface= "Com.ws.services.IHelloServices")    public class helloservicesimpl  implements ihelloservices {          public string[]  gethellowords ()  {           string[] words  = {"Hello vicky.", "Hello,i ' M vicky.", "Hi,ivy and simon."};            return words;        }          public string sayhello (string name)  {           return  "hello " +name+ " !   ";       }          public string sayhellotoall (string[]  UserNames)  {           String hello =  " hello  ";           for (int i=0;i< usernames.length;i++) {               if (i !=usernames.length-1)                     hello += usernames[i]+ " and ";                else                    hello += usernames[i]+ "&NBSP;.";            }            return hello;       }     }  

 3, create WebServices server, and publish service
[Java]   View plain copy package com.test;      

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.