定义接口
packagecom.amwu.v1;
import java.util.Date;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style = Style.RPC)
public interface IWs {
@WebMethod
public abstract String say(String name);
/* @WebMethod
public abstract List<Date> getSomeDate(); //不支持集合类
*/
public String[] getNames();
public Date[] getDate();
public Man getMan();//支持自定义类型
}
实现接口
@WebService(endpointInterface="com.amwu.v1.IWs")
public class Ws implements IWs {
/* (non-Javadoc)
* @see com.amwu.v1.IWs#say(java.lang.String)
*/
public String say(String name) {
return "您好:" + name;
}
/* (non-Javadoc)
* @see com.amwu.v1.IWs#getSomeDate()
*/
public List<Date> getSomeDate(){
List<Date> res=new ArrayList<Date>();
for(int i=0;i<10000;i++){
res.add(new Date());
}
return res;
}
public Man getMan() {
// TODO Auto-generated method stub
return new Man("amwu",28,"M",false);
}
public String[] getNames() {
return Arrays.asList("amwu","xjg").toArray(new String[1]);
}
public Date[] getDate() {
Date[] d=new Date[2];
d[0]=new Date();
d[1]=new Date();
return d;
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Log4j
public class Man {
private String name;// 姓名
private int age;
private String sex;
private boolean haveGF;
public Man(Man man) {
this.age = man.age;
this.name = man.name;
this.sex = man.sex;
}
}
注:如果该实现类只是实现了一个接口,可以不定endpointInterface,如果实现了多个接口,而只是想返回一个接口的web服务方法就需要写一下了。
发布:
public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:9876/ts", new Ws()); //单例的
}
研究,在不增加jar包的前提共享 80 端口。
有些服务器由于安全,防火墙的原因只给开放了少数的端口
---------可以与tomcat一起共享80端口
package com.amwu;
import java.net.MalformedURLException;
import java.util.Enumeration;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.xml.ws.Endpoint;
public class WSListener implements ServletContextListener {
private static final long serialVersionUID = 1L;
Endpoint ws;
//ServletContextListener
@Override
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("停止webserive");
ws.stop();
}
@Override
public void contextInitialized(ServletContextEvent sce) {
System.out.println("启动webserive");
String ctx=sce.getServletContext().getContextPath();
String tomcatPort=sce.getServletContext().getInitParameter("tomcatPort");
System.out.println(tomcatPort);
String wsdl="http://127.0.0.1:"+tomcatPort+ctx+"/ws";
System.out.println("wsdl:"+wsdl);
ws = Endpoint.publish(wsdl, new Ws()); //单例的
}
}
动态代理
分享到:
相关推荐
rar中包含整个项目的源码和数据库生成脚本,采用jax-ws发布Web Service服务,支持java客户端和.Net客户端调用,数据库采用oracle10g,里面有创建数据库脚本文件createTable_Oracle10g.sql,由于Hibernate映射表中会...
jax-ws metro web service eclipse sample. 1 服务端 AddNumbersImpl.java 2 客户端 AddNumbersClient.java 3 启动器 AddWebserviceLauncher.java
JAX-WS Web service 开发初步
学习JAX-WSWebService开发相关文档及Myeclipse开发方法。
Spring应用开发实战,光盘中附录B,包含Web Service WS的详细讲解。
Web Service 官方文档,详细地描述了Web Service的所有协议。
JAX-WS_开发_web_service.txt
jax-wswebservice注解详解[整理].pdf
JAX-WS_开发_web_service JAX-WS_开发_web_service
使用Myeclipse-8.5开发基于JAX-WS的Web-service实例.docx
Asynchronous Web Service Invocation with JAX-WS 2.0
NULL 博文链接:https://yimengzhu.iteye.com/blog/1879330
2.3发布Web Service 2.3.1在应用程序中发布 2.3.2在Web应用程序中发布 2.3.2.1 依赖包 2.3.2.1发布步骤 2.4 创建Web Service客户端 2.4.1同步调用方式的客户端 2.4.1.1 开发步骤 2.4.1.2 运行...
基于jax-ws 实现的web service client和server端的demo程序。 注:如果使用的是 myeclipse 时 server 部署到tomcat 启动的时候会报错 解决办法:找到myeclipse安装目录下的 plugins 目录里 查找 webservices-rt.jar,...
原来的jax-ws不知道为什么总是不成功,最后放弃,换成这个。具体过程可以参考官网:http://docs.spring.io/spring-ws/site/reference/html/tutorial.html
An Excellent presentation on web services orchestration and ws-bpel 2.0
这时一个用java语言调用气象台的获取天气信息的web service
Java Web Service Clients examples(SOAP,AXIS)