首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

webservice 公布的接口不能使“多态”

2013-11-30 
webservice 发布的接口不能使“多态”1、定义一个多态的接口package hbimport javax.jws.WebParamimport ja

webservice 发布的接口不能使“多态”

1、定义一个多态的接口

package hb;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic interface IHelloWorldService {    public String sayHello(@WebParam(name = "name") String name);        public String sayHello(@WebParam(name = "name") String name,@WebParam(name = "country") String country);}

?

2、定义一个对接口的实现类

package hb;import javax.jws.WebParam;import javax.jws.WebService;import javax.jws.soap.SOAPBinding;import javax.jws.soap.SOAPBinding.Style;@WebService@SOAPBinding(style = Style.RPC)public class HelloWorldService implements IHelloWorldService {public String sayHello(@WebParam(name = "name") String name) {return name + " say: Hello World ";}@Overridepublic String sayHello(@WebParam(name = "name") String name,@WebParam(name = "country") String country) {System.out.println("public String sayHello(@WebParam(name = "name") String name," +"@WebParam(name = "country") String country)");return null;}}

?

3、发布webservice

package hb;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;public class HelloWorldServiceClient {        public static void main(String[] args) {        //调用WebService        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();        factory.setServiceClass(IHelloWorldService.class);        factory.setAddress("http://localhost:9000/helloWorld");                IHelloWorldService service = (IHelloWorldService) factory.create();        System.out.println("[result]" + service.sayHello("huangbiao"));    }}

?

启动服务会报错:An operation with name [{http://hb/}sayHello] already exists in this service;即该接口已经发布了,解决办法就是保证对外提供的接口名称必须是唯一的。

?

解决办法:修改接口,保证名称唯一。

package hb;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic interface IHelloWorldService {    public String sayHello(@WebParam(name = "name") String name);        public String sayHello1(@WebParam(name = "name") String name,@WebParam(name = "country") String country);}

?

?

?

热点排行