java webservice 调用

来源:互联网 发布:小甲鱼c语言新版 编辑:程序博客网 时间:2024/06/05 20:15
package com.cxf.impl;


import javax.jws.WebService;
import javax.xml.ws.Endpoint;


import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;


import com.cxf.interfaces.HelloWorldServiceInf;


@WebService(endpointInterface="com.cxf.interfaces.HelloWorldServiceInf",serviceName="helloWorldService")
public class Server implements HelloWorldServiceInf {


public String sayHello(String username) {
return "Hello,"+username;
}
public static void main(String[] args) {

/***************************以下为方法一 ****************************

Server impl=new Server();
JaxWsServerFactoryBean factoryBean=new JaxWsServerFactoryBean();
factoryBean.setAddress("http://localhost:9000/hello");
factoryBean.setServiceClass(HelloWorldServiceInf.class);
factoryBean.setServiceBean(impl);
factoryBean.getInInterceptors().add(new LoggingInInterceptor());
factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
factoryBean.create();*/

/***************************以下为方法二****************************/

Server impl=new Server();
String address="http://localhost:9000/hello";
Endpoint.publish(address, impl);
}
}
0 0
原创粉丝点击