`

cxf webservice

阅读更多

cxf version:2.7.11

java version:jre1.7x

 

server:

/**需要导入cxflib下面的所有的jar*/

package com.wdh.ws.cxf;

 

import javax.jws.WebService;

 

 

@WebService

public interface IHelloService {

 

String sayHello(String name);

}

 

package com.wdh.ws.cxf;

 

public class HelloServiceImpl implements IHelloService {

 

@Override

public String sayHello(String name) {

return "hello " + name;

}

 

}

 

package com.wdh.ws.cxf;

 

import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

 

 

/**

 * 发布webservice

 * */

public class PublishWS {

 

public static void  main(String[] args) {

JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();

factory.setAddress("http://192.168.1.116:8964/hello");

/**指向接口*/

factory.setServiceClass(IHelloService.class);

/**指向实现类*/

factory.setServiceBean(new HelloServiceImpl());

 

/**启动webservice*/

factory.create();

}

}

 

client:

/**生成客户端代理及其相关对象*/

D:\apache-cxf-2.7.11\bin>wsdl2java -d e: -p package_nanme -client wsdl

 

package com.wdh.ws.cxf;

 

public class WSTest {

 

public static void main(String[] args) {

IHelloServiceService helloServiceService = new IHelloServiceService();

IHelloService helloService = helloServiceService.getIHelloServicePort();

String ret = helloService.sayHello("jack");

System.out.println(ret);

 }

}

 

  • 大小: 59.5 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics