CFX-based WebService invocation

Source: Internet
Author: User
Tags webservice annotation wsdl

One, simple (combined with spring)

1. Create a new Web project to add the jar required by CFX

2. Write the Web service interface to be published and the jar required to implement the class

Interface class HelloWorld:

1 ImportJavax.jws.WebService;2 @WebService3  Public InterfaceHelloWorld4 {5      Publicstring SayHello (string text);6 }7 Implement class Helloworldimpl:8 ImportJavax.jws.WebService;9@WebService (endpointinterface= "Hello. HelloWorld ")Ten  Public classHelloworldimplImplementsHelloWorld One { A @Override -      Publicstring SayHello (string text) { -         return"Hello," +text; the     } -}
View Code

Implement class Helloworldimpl:

1 ImportJavax.jws.WebService;2@WebService (endpointinterface= "Hello. HelloWorld ")3  Public classHelloworldimplImplementsHelloWorld4 {5 @Override6      Publicstring SayHello (string text) {7         return"Hello," +text;8     }9}
View Code

@WebService annotation indicates that the Web service is to be published

3. Configure the Web Service to be published in Applicationcontext_cfx.xml

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:jaxws= "Http://cxf.apache.org/jaxws"4 xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">5     <ImportResource= "Classpath:meta-inf/cxf/cxf.xml" />6 <!--<import resource= "Classpath:meta-inf/cxf/cxf-extension-soap.xml"/>7   -    <ImportResource= "Classpath:meta-inf/cxf/cxf-servlet.xml" />8     <BeanID= "Hello"class= "Hello." Helloworldimpl " />9     <Jaxws:endpointID= "HelloWorld"implementor= "Hello." Helloworldimpl "Ten Address= "/helloworld" /> One </Beans>
View Code

Note:<jaxws:endpoint id= "HelloWorld" implementor= "#hello" address= "/helloworld"/> ID: Refers to the spring-configured The ID of the bean.  Implementor: Indicates the specific implementation class. Address: Indicates the relative addresses of this Web service

4. Configure the Web. xml file

1 <Context-param>2         <Param-name>Contextconfiglocation</Param-name>3     <Param-value>Classpath*:applicationcontext*.xml</Param-value>4     </Context-param>5     <Listener>6         <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>7     </Listener>8     <servlet>9         <Servlet-name>Cxfservlet</Servlet-name>Ten         <Servlet-class>Org.apache.cxf.transport.servlet.CXFServlet</Servlet-class> One         <Load-on-startup>1</Load-on-startup> A     </servlet> -     <servlet-mapping> -         <Servlet-name>Cxfservlet</Servlet-name> the         <Url-pattern>/services/*</Url-pattern> -     </servlet-mapping>
View Code

5. Deploy to the Tomcat server, enter: http://localhost:8080/<web-app-name>/helloworld?wsdl, the WSDL for this Web service will be displayed.

Note: If the Web. XML Configuration <servlet-name>CXFServlet</servlet-name> <url-pattern>/ws/*</url-pattern> The access address is: HTTP://LOCALHOST:8080/<WEB-APP-NAME>/WS/HELLOWORLD?WSDL

CFX-based WebService invocation

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.