项目目录结构如下
加载JAX-WS的jar包
1:TestService文件内容如下
package com.test.service;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
@javax.jws.WebService(targetNamespace = "http://server.mrotest.com/", serviceName = "MROService", portName = "MROPort")
public class TestService {
@WebMethod
@SOAPBinding(style = SOAPBinding.Style.RPC)
public void getName(){
System.out.println("=========================================");
}
}
2:sun-jaxws.xml文件内容如下
<?xml version = "1.0"?>
<endpoints version="2.0"
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
<endpoint name="MROPort"
implementation="com.test.service.TestService"
url-pattern="/MROPort">
</endpoint>
</endpoints>
3:web.xml文件内容如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>DocumentReSend_WEBSERVICE</display-name>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<description>JAX-WS endpoint - QRQCService</description>
<display-name>MROService</display-name>
<servlet-name>MROService</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MROService</servlet-name>
<url-pattern>/MROPort</url-pattern>
</servlet-mapping>
</web-app>
部署到tomcat,在浏览器输入。http://localhost:8080/项目名/MROPort,出现下面内容说明成功
访问成功之后需要生成客户端代码可以参考此博文:https://blog.csdn.net/qq_36880602/article/details/78759845