简述
使用IDEA开发webservice服务,从零开始一步一步指引你。
服务端开发
首先创建一个webservice项目,如下图
创建完项目后idea会帮我们创建一个类,helloword,我们把它删掉。
接下来新建一个接口
1 package com.webservice.demo; 2 ?3 import javax.jws.WebService; 4 ?5 /** 6 ?* demo 7 ?* 8 ?* @author GaoFei 9 ?* Create by 2018/1/3110 ?*/11 @WebService12 public interface DemoServer {13 ????Double sum(Double a, Double b);14 15 ????Double minus(Double a, Double b);16 17 ????Double ride(Double a, Double b);18 19 ????Double divide(Double a, Double b);20 }
然后创建接口的实现类并实现加减乘除4个方法。
1 package com.webservice.demo.impl; 2 ?3 import com.webservice.demo.DemoServer; 4 ?5 import javax.jws.WebService; 6 import javax.xml.ws.Endpoint; 7 ?8 /** 9 ?* annotation10 ?*11 ?* @author GaoFei12 ?* Create by 2018/1/3113 ?*/14 @WebService(serviceName = "DemoServer", endpointInterface = "com.webservice.demo.DemoServer")15 public class DemoServerImpl implements DemoServer {16 17 ????public static void main(String args[]) {18 ????????Endpoint.publish("http://localhost:9000/DemoServer", new DemoServerImpl());19 ????}20 21 ????/**22 ?????* 加23 ?????*24 ?????* @author GaoFei25 ?????* Create by 2018-01-3126 ?????*/27 ????@Override28 ????public Double sum(Double a, Double b) {29 ????????return a + b;30 ????}31 32 ????/**33 ?????* 减34 ?????*35 ?????* @author GaoFei36 ?????* Create by 2018-01-3137 ?????*/38 ????@Override39 ????public Double minus(Double a, Double b) {40 ????????return a - b;41 ????}42 43 ????/**44 ?????* 乘45 ?????*46 ?????* @author GaoFei47 ?????* Create by 2018-01-3148 ?????*/49 ????@Override50 ????public Double ride(Double a, Double b) {51 ????????return a * b;52 ????}53 54 ????/**55 ?????* 除56 ?????*57 ?????* @author GaoFei58 ?????* Create by 2018-01-3159 ?????*/60 ????@Override61 ????public Double divide(Double a, Double b) {62 ????????return a / b;63 ????}64 }
然后修改/web/WEB-INF/sun-jaxws.xml。
1 <?xml version="1.0" encoding="UTF-8"?>2 3 <endpoints xmlns=‘http://java.sun.com/xml/ns/jax-ws/ri/runtime‘ version=‘2.0‘>4 ????<endpoint5 ????????????name=‘DemoServer‘6 ????????????implementation=‘com.webservice.demo.impl.DemoServerImpl‘7 ????????????url-pattern=‘/services/DemoServer‘/>8 </endpoints>
最后运行main方法。
至此,服务端就开发完成了。
客户端开发
首先新建一个webservice client项目。
调用
运行结果
WebService_Demo
原文地址:https://www.cnblogs.com/gaofei-1/p/8395089.html