使用CXF开发WebService服务器端和客户端

开发需要的jar包:
[img]http://dl.iteye.com/upload/attachment/0079/1739/759f65f5-3cce-36dc-a151-4d333e37248a.jpg[/img]
服务器端代码:

package com.cxf.ws.service;

import javax.jws.WebService;

@WebService
public interface HelloWorld {
public String sayHello(String name);
}


package com.cxf.ws.service.impl;


import javax.jws.WebService;
import com.cxf.ws.service.HelloWorld;

@WebService(endpointInterface="com.cxf.ws.service.HelloWorld",serviceName="HelloWorldImpl")
public class HelloWorldImpl implements HelloWorld{
@Override
public String sayHello(String name) {
return "hello,"+name+"!";
}
}


package com.cxf.ws.app;

import javax.xml.ws.Endpoint;

import com.cxf.ws.service.HelloWorld;
import com.cxf.ws.service.impl.HelloWorldImpl;


public class Server {

public static void main(String[] args) {
// JaxWsServerFactoryBean factoryBean=new JaxWsServerFactoryBean();
// factoryBean.setAddress("http://192.168.0.251:9999/CXF-WS-Server");
// factoryBean.setServiceClass(HelloWorld.class);
// factoryBean.setServiceBean(new HelloWorldImpl());
// factoryBean.create();
HelloWorld hw=new HelloWorldImpl();
Endpoint.publish("http://192.168.0.251:9999/CXF-WS-Server", hw);
System.out.println("发布成功!");
}

}


配置wsdl2java环境:
path:D:\apache-cxf-2.5.8\bin
cmd 命令:
切换目录到客户端工程的src下
wsdl2java http://192.168.0.251:9999/CXF-WS-Server/HelloWorld?wsdl
客户端代码:

package com.cxf.ws.app;

import com.cxf.ws.service.HelloWorld;
import com.cxf.ws.service.impl.HelloWorldImpl;

public class Client {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HelloWorldImpl fac=new HelloWorldImpl();
HelloWorld hw=fac.getHelloWorldImplPort();
String word=hw.sayHello("金聪敏");
System.out.println(word);
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值