版权声明:内容记录学习过成文章,仅供参考 https://blog.csdn.net/qq_40195958/article/details/83106781
创建service接口
/**
*
* @author DongWei
* 2018年10月17日
*/
@WebService
public interface IMYService {
/**
* 加法接口
* 2018年10月17日
*/
public int add(int a,int b);
/**
* 减法接口
*/
public int minit(int a,int b);
创建实现类
/**
*
* @author DongWei 2018年10月17日
*/
public class ServerClient {
public static void main(String[] args) {
/*
* 这种发布缺点是,首先要知道接口类名称,
* 其次是不能够跨平台
*/
// 创建访问路径
try {
URL url = new URL("http://127.0.0.1:12345/ns?wsdl");
// 通过QName知名服务信息
QName qName = new QName("http://service.ottc.org/", "MyServiceImplService");
// 创建服务
Service service = Service.create(url, qName);
// 通过服务获取类
IMYService serv = service.getPort(IMYService.class);
int num = serv.add(23, 57);
System.out.println(num);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}