zoukankan      html  css  js  c++  java
  • WbeService CXF (1)

    CXF官方网址:http://cxf.apache.org/

    1.首先,需要配置好java环境!

    2.软件可以使用eclipse(需要装tomcat插件)或者myeclipse

    3.还要下apache-cxf-2.6.2 支持jar包 下载地址:http://www.apache.org/dyn/closer.cgi?path=/cxf/2.3.3/apache-cxf-2.3.3.zip

    准备好了工作环境之后,就准备开始编写第一个CXF了!

    第一步:创建一个HelloWord接口

    import javax.jws.WebMethod;  
    import javax.jws.WebParam;  
    import javax.jws.WebResult;  
    import javax.jws.WebService;  
     
    @WebService 
    public interface HelloWorld {  
        @WebMethod 
        @WebResult String sayHi(@WebParam String text);  
    } 

    第二步:实现HelloWord接口

    public class HelloWorldImpl implements HelloWorld {  
         
        public String sayHi(String name) {  
            String msg = "Hello " + name + "!";  
            return msg;  
        }  
    } 

    第三步:创建一个服务类

    import org.apache.cxf.jaxws.JaxWsServerFactoryBean;  
     
    // http://localhost:8080/HelloWorld?wsdl  
    public class Server {  
        public static void main(String[] args) throws Exception {  
            JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();  //创建一个JAXWS服务工厂
            factory.setServiceClass(HelloWorldImpl.class);                  //设置需要服务的已重新的接口
              
            factory.setAddress("http://localhost:8080/HelloWorld");         //设置地址
            factory.create();                            //创建工厂
     
            System.out.println("Server start...");  
            //Thread.sleep(60 * 1000);  
           // System.out.println("Server exit...");  
           // System.exit(0);  
        }  
    } 

    第四步:创建一个客户端,为了方便测试,但也可以再游览器地址打:http://localhost:8080/HelloWorld?wsdl 来检查是否能够解析

    public class Client {  
        public static void main(String[] args) {  
            JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();  
            factory.setServiceClass(HelloWorld.class);  
            factory.setAddress("http://localhost:8080/HelloWorld");  
            HelloWorld helloworld = (HelloWorld) factory.create();  
            System.out.println(helloworld.sayHi("sdads"));  
            System.exit(0);  
        }  
    } 

    如果在地址打上 http://localhost:8080/HelloWorld?wsdl 会看到xml结构文档树

    到此为止,第一个CXF的HelloWord的练习就到这里了!!

    2012/8/28

  • 相关阅读:
    hdu 4813(2013长春现场赛A题)
    NEFU 628 Garden visiting (数论)
    FZU 2020 组合 (Lucas定理)
    HDU 3304 Interesting Yang Yui Triangle (Lucas定理)
    HDU 3037 Saving Beans (数论,Lucas定理)
    UVa 1161 Objective: Berlin (最大流)
    Vijos P1951 玄武密码 (AC自动机)
    LA 4670 Dominating Patterns (AC自动机)
    HDU 2340 Obfuscation (暴力)
    HDU 5510 Bazinga (KMP)
  • 原文地址:https://www.cnblogs.com/yyman001/p/2659841.html
Copyright © 2011-2022 走看看