使用JDK创建webService

1、建一个接口类

package ws;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface HelloWS {
	
	@WebMethod
	public String sayHello(String name);
}

2、建一个实现类

package ws;
import javax.jws.WebService;

@WebService
public class HelloWSImpl implements HelloWS {

	@Override
	public String sayHello(String name) {
		// TODO Auto-generated method stub
		System.out.println("Server" + name);
		return "Hello"+name;
	}
}

3、发布测试类

package ws;
import javax.xml.ws.Endpoint;

public class ServerTest {
	public static void main(String[] args) {
		String addreess = "http://localhost:8080/hellows";
		Endpoint.publish(addreess, new HelloWSImpl());
		System.out.println("发布成功");
	}
}

4、调用成功

  浏览器访问:http://localhost:8080/hellows

 

posted @ 2021-08-05 09:37  信铁寒胜  阅读(113)  评论(0编辑  收藏  举报