说明:
先下载apache-cxf-2.2.3.zip;
把 \apache-cxf-2.2.3\apache-cxf-2.2.3\lib下jar
文件导入到项目中;

package javaws;


import javax.jws.WebService;


@WebService

public
interface HelloWorld

{

public String SayHello(String name);

}

package javaws;


import javax.jws.WebService;


@WebService

public
class HelloWorldImpl implements HelloWorld

{


public String SayHello(String name)

{

Sy
stem.
out.println(
"sevice is called!");

return
"hello,"+name;

}


}
3.服务器端:

package javaws;

import org.apache.cxf.frontend.Server
factorybean;


public
class MainServer

{

public
static
void main(String[] args)

{


HelloWorldImpl helloworldImpl =
new HelloWorldImpl();

Server
factorybean svrFactory =
new Server
factorybean();

svrFactory.setServiceClass(HelloWorld.
class);

svrFactory.setAddress(
"http://localhost:8888/Hello");

svrFactory.setServiceBean(helloworldImpl);

svrFactory.create();


}


}
4.客户端:

package javaws;

import org.apache.cxf.frontend.ClientProxy
factorybean;


public
class TestClient

{


public
static
void main(String[] args)

{


ClientProxy
factorybean factory =
new ClientProxy
factorybean();

factory.setServiceClass(HelloWorld.
class);

factory.setAddress(
"http://localhost:8888/Hello");

HelloWorld client = (HelloWorld)factory.create();

System.out.println("Invoke sayHi()....");

System.out.println(client.SayHello("tiger"));


}


}
运行时要先启动服务器端,在运行客户端,就可以看到
调用服务的
效果了。
这只是入门级的体验,记录备查,有待深入学习!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。