## 摘要
网上搜索WebService文章的时候,发现这已经是比较老旧的东西了, 现在都直接用微服务的架构来替代了。 但是无奈新公司还是经常要用到这个。 弄了半天,发现用Eclipse 开发时候,JDK1.8 发布不出来,不知道是否因为1.8的发布需要额外配置什么,还是得使用Eclipse自带的JDK。还希望有高人指点一下。
直接上代码——Server
补充一句, 先上个简单的。 希望有大牛多多指正。
- 接口
package gd2h.server;
import javax.jws.WebService;
@WebService
public interface IMyService {
public int add(int a,int b);
public int minus(int a,int b);
}
- 实现类
package gd2h.server;
import javax.jws.WebService;
@WebService(endpointInterface = "gd2h.server.IMyService")
public class IMyServiceImp implements IMyService {
@Override
public int add(int a, int b) {
System.out.println(a+"+b="+(a+b));
return a+b;
}
@Override
public int minus(int a, int b) {
System.out.println(a+"-b="+(a-b));
return a-b;
}
}
- server
package gd2h.server;
import javax.xml.ws.Endpoint;
public class MyServer {
public static void main(String[] args) {
String address="http://127.0.0.1:6688/ws";
Endpoint.publish(address, new IMyServiceImp());// 发布接口的实现类
System.out.println("ServiceTest已启动");
}
}
直接上代码——Client
package gd2h.server;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class TestClient {
public static void main(String[] args) {
try {
URL url = new URL("http://127.0.0.1:6688/ws?wsdl");
QName anme=new QName("http://server.gd2h/", "IMyServiceImpService");
Service service=Service.create(url, anme);
IMyService iMyService= service.getPort(IMyService.class);
System.out.println(iMyService.add(1, 2));
System.out.println(iMyService.add(3, 1));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
wsimport 导入方式引用
- 新建工程
- 导入wsimport得到的包
- 测试是否能直接导入
package test;
import gd2h.server.IMyService;
import gd2h.server.IMyServiceImpService;
public class Test {
public static void main(String[] args) {
IMyServiceImpService imService= new IMyServiceImpService();
IMyService ImS= imService.getIMyServiceImpPort();
System.out.println(ImS.add(1, 2));
System.out.println(ImS.add(3, 1));
}
}
最后附上
原文:
1:jetty各个版本信息
版本号 | 发布及维护年份 | 托管平台 | JVM版本 | 支持的协议 | servlet版本 | JSP版本 | 目前状态 |
---|---|---|---|---|---|---|---|
9.3 | 2015 | Eclipse | 1.8 | HTTP/1.1 (RFC 7230), HTTP/2 (RFC 7540), WebSocket (RFC 6455, JSR 356), FastCGI | 3.1 | 2.3 | Stable |
9.2 | 2014 | Eclipse | 1.7 | HTTP/1.1 RFC2616,javax.websocket, SPDY v3 | 3.1 | 2.3 | Stable |
8 | 2009-至今 | Eclipse/Codehaus | 1.6 | HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3 | 3.0 | 2.2 | Mature |
7 | 2008-至今 | Eclipse/Codehaus | 1.5 | HTTP/1.1 RFC2616, WebSocket RFC 6455, SPDY v3 | 2.5 | 2.1 | Mature |
6 | 2006-2010 | Codehaus | 1.4-1.5 | HTTP/1.1 RFC2616 | 2.5 | 2.0 | Venerable |
5 | 2003-2009 | Sourceforge | 1.2-1.5 | HTTP/1.1 RFC2616 | 2.4 | 2.0 | Deprecated |
4 | 2001-2006 | Sourceforge | 1.2,J2ME | HTTP/1.1 RFC2616 | 2.3 | 1.2 | Ancient |
3 | 1999-2002 | Sourceforge | 1.2 | HTTP/1.1 RFC2068 | 2.2 | 1.1 | Fossilized |
2 | 1998-2000 | Mortbay | 1.1 | HTTP/1.0 RFC1945 | 2.1 | 1.0 | Legendary |
1 | 1995-1998 | Mortbay | 1.0 | HTTP/1.0 RFC1945 | – | – | Mythical |
2:jdk编译器版本对应的数字版本号
jdk编译器版本 | 十进制(minor.major) | 十六进制(minor.major ) |
---|---|---|
1.8 | 52 | 00 00 00 34 |
1.7 | 51 | 00 00 00 33 |
1.6 | 50 | 00 00 00 32 |
1.5 | 49 | 00 00 00 31 |
1.4 | 48 | 00 00 00 30 |
1.3 | 47 | 00 00 00 2F |
1.2 | 46 | 00 00 00 2E |
1.1 | 45 | 00 00 00 2D |
更新记录2016-06-01更新jetty9.3对应jvm版本