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

1、定义一个多态的接口

package hb;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public 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 ";
	}

	@Override
	public 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;

@WebService
public interface IHelloWorldService {
    public String sayHello(@WebParam(name = "name") String name);
    
    public String sayHello1(@WebParam(name = "name") String name,@WebParam(name = "country") String country);
}

 

阅读更多
个人分类: webservice & cxf
上一篇cxf 发布多个接口的方法
下一篇excel中怎么使除了内容以外的单元格,变成没有格,成白色空白
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭