Java 基于web service 暴露接口 供外部调用

时间:2023-03-09 08:37:55
Java  基于web service 暴露接口 供外部调用
package cn.zr.out.outinterface;

import java.text.SimpleDateFormat;
import java.util.Date; import javax.jws.WebService;
import javax.xml.ws.Endpoint; @WebService(name="webSer",serviceName="userWebService",targetNamespace="outws")
public class OutInterface { public static void main(String[] args) {
Endpoint.publish("http://localhost:9865/", new OutInterface());
System.out.println("=== 程序正在运行 ===");
} public String outService(String info) {
String msg = "暴露接口"+info;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String currentTime = format.format(new Date());
System.out.println(msg+",调用时间:"+currentTime);
return msg;
}
}

然后在浏览器上输入http://localhost:9865/webSer?wsdl,会出现如下信息:

Java  基于web service 暴露接口 供外部调用