• 基于cfx的webservice调用


    一、简单的(结合Spring)

    1、  新建一个web 项目,加入cfx所需要jar 

    2、  编写要发布的Web Service接口和实现类所需要jar 

    接口类 HelloWorld :

     1 import javax.jws.WebService;
     2 @WebService
     3 public interface HelloWorld
     4 {
     5     public String sayHello(String text);
     6 }
     7 实现类HelloWorldImpl :
     8 import javax.jws.WebService;
     9 @WebService(endpointInterface="hello.HelloWorld")
    10 public class HelloWorldImpl implements HelloWorld
    11 {
    12     @Override
    13     public String sayHello(String text){
    14         return "Hello, " + text;
    15     }
    16 }
    View Code

    实现类HelloWorldImpl :

    1 import javax.jws.WebService;
    2 @WebService(endpointInterface="hello.HelloWorld")
    3 public class HelloWorldImpl implements HelloWorld
    4 {
    5     @Override
    6     public String sayHello(String text){
    7         return "Hello, " + text;
    8     }
    9 }
    View Code

    @WebService 注解表示是要发布的web 服务

    3、  在applicationContext_cfx.xml配置要发布的Web Service

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="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     <import resource="classpath:META-INF/cxf/cxf.xml" />
     6 <!--     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
     7  -->    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
     8     <bean id="hello" class="hello.HelloWorldImpl" />
     9     <jaxws:endpoint id="helloWorld" implementor=" hello.HelloWorldImpl "
    10         address="/HelloWorld" />
    11 </beans>
    View Code

    注意:<jaxws:endpoint id="helloWorld" implementor="#hello"           address="/HelloWorld" />   id:指在spring配置的bean的ID. Implementor:指明具体的实现类.  Address:指明这个web service的相对地址

    4、 配置web.xml文件

     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>
    10         <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    11         <load-on-startup>1</load-on-startup>
    12     </servlet>
    13     <servlet-mapping>
    14         <servlet-name>CXFServlet</servlet-name>
    15         <url-pattern>/services/*</url-pattern>
    16     </servlet-mapping>
    View Code

    5、 部署到tomcat服务器,输入:http://localhost:8080/<web-app-name>/ HelloWorld?wsdl,将显示这个web service的wsdl.

     注意:如果web.xml配置<servlet-name>CXFServlet</servlet-name>           <url-pattern>/ws/*</url-pattern>   则访问地址为:http://localhost:8080/<web-app-name>/ws/ HelloWorld?wsdl

     

  • 相关阅读:
    Cisco产品采用的网络协议总结 java程序员
    实用级反主动防御rootkit设计思路 java程序员
    教你几招识别和防御Web网页木马 java程序员
    “TRUNK”的三个意思 不要混淆 java程序员
    Windows 图像捕获服务本地权限提升漏洞 java程序员
    入侵检测之蜜罐 java程序员
    小措施防范来自网络的ARP攻击 java程序员
    poj2299UltraQuickSort
    按位与或非
    hdu4325(线段树)
  • 原文地址:https://www.cnblogs.com/ld-swust/p/5126199.html
Copyright © 2020-2023  润新知