码迷,mamicode.com
首页 > Web开发 > 详细

webService-cxf

时间:2014-05-21 23:26:17      阅读:479      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

官网必备包,自己研究api:http://cxf.apache.org/download.html

 

然后就是一个简单的例子了:

  先服务端:

    

bubuko.com,布布扣
package com.cxf;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface IHelloWorld {

    public String sayHi(@WebParam(name="text")String text);
}
bubuko.com,布布扣
bubuko.com,布布扣
package com.cxf;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public class HelloWorld implements IHelloWorld {

    public String sayHi(@WebParam(name="text") String text){
        return "sayHi:"+text;
    }
}
bubuko.com,布布扣
bubuko.com,布布扣
package com.cxf;

import javax.xml.ws.Endpoint;

public class ServerSimple {

    public ServerSimple() throws Exception{
        System.out.println("starting Server");
        HelloWorld h=new HelloWorld();
        String address="http://localhost:9000/helloWorld";
        Endpoint.publish(address, h);
    }
    public static void main(String[] args) throws Exception{
        new ServerSimple();
        System.out.println("server ready...");
        Thread.sleep(60*1000);
        System.exit(0);
    }
}
bubuko.com,布布扣

 

然后客户端:

 

bubuko.com,布布扣
package com.cxf;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;



public final class Client {

    private Client(){}
    public static void main(String[] args) {
        JaxWsProxyFactoryBean factory=new JaxWsProxyFactoryBean();
        factory.setServiceClass(IHelloWorld.class);
        factory.setAddress("http://localhost:9000/helloWorld");
        IHelloWorld client=(IHelloWorld)factory.create();
        System.out.println("Invoke sayHi()....");
        System.out.println(client.sayHi(System.getProperty("user.name")));
        System.exit(0);
    }
}
bubuko.com,布布扣

 

  至于关于什么是webservice什么的,请参考http://www.w3school.com.cn/ws.asp

  共同进步,共同学习

 

 

webService-cxf,布布扣,bubuko.com

webService-cxf

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/huzi007/p/3739082.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!