Spring's WebService development

Source: Internet
Author: User
Tags wsdl

Because the project was developed using spring, the author chose Apache CXF for WebService development, because the Apache CXF provides a convenient spring integration method that can be annotated,  Spring-tagged configuration to expose Web services and Consumer Web services. 
1.  first go to http://cxf.apache.org/download.html to download the latest version (currently 2.4.1)   
2.  Import the appropriate package into the project, presumably the following package:
Commons-logging-1.1.1.jar
Geronimo-activation_1.1_spec-1.0-m1.jar (or Sun ' s activation jar)
Geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
Geronimo-javamail_1.4_spec-1.7.1.jar (or Sun ' s javamail jar)
Geronimo-servlet_3.0_spec-1.0.jar (or Sun ' s servlet jar)
Geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
Jaxb-api-2.1.jar
Jaxb-impl-2.1.13.jar
Jaxws-api-2.1.jar
Neethi-3.0.0.jar
Saaj-api-1.3.jar
Saaj-impl-1.3.jar
Stax-api-1.0.1.jar
Stax2-api-3.1.1.jar
Wsdl4j-1.6.2.jar
Woodstox-core-asl-4.0.8.jar
Xmlschema-core-2.0.jar
Xml-resolver-1.2.jar
Cxf-2.4.0.jar
Spring 's bag will not be said. 
3.  Create a new interface

@WebService

Public Interface helloworldservice {

Public string Getnewname (string userName);

}
Use @WebService identity to let cxf know to use this interface to create WSDL  
4.  Create a new implementation class

@WebService(endpointinterface="Org.app.demo.spring.service.HelloWorldService")

Public class Helloworldserviceimpl implements helloworldservice {

Public string Getnewname (String userName) {

return "Hello spring!" + userName;

}

}
5.  Modify the appropriate configuration file
Add the following code to the applicationcontext.xml

<jaxws:endpoint

id="HelloWorld"

implementor="Org.app.demo.spring.service.impl.HelloWorldServiceImpl"

address="/helloworld" /> 
Or
<bean id= " helloworldservice" class= " org.app.demo.spring.service.impl.HelloWorldServiceImpl"/ >   

<jaxws:endpoint

id="HelloWorld"

implementor="#helloWorldService"

address="/helloworld" /> 
Note: TheXML header file needs to be added accordingly
Xmlns:jaxws= "Http://cxf.apache.org/jaxws
Http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
Add the following code to Web. xml

<servlet>

<servlet-name>cxfservlet</servlet-name>

<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

<load-on-startup>2</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>cxfservlet</servlet-name>

<url-pattern>/*</url-pattern>

</servlet-mapping>
6.  start Tomcat and open the http://localhost:8080/myapp/HelloWorld?wsdl to see  
7.  Client invocation is also very convenient, the following code:

URL wsdlurl = new url ("http://192.168.0.114:8080/myapp/HelloWorld?wsdl");

QName service_name = new QName ("http://impl.service.spring.demo.app.org/"," Helloworldserviceimplservice ");

Service service = service. Create (Wsdlurl, service_name);

HelloWorldService Hello = Service.getport (helloworldservice. Class);

System.  out . println (Hello.getnewname ("WebService call "));    
Then after executing the code, the  Hello spring! is printed out WebService called . 
1. Address of the server with IP address WebService. 
The corresponding interface must be copied to the client project.

Spring's WebService development

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.