上代码~
pom.xml:添加依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web-services</artifactId></dependency>
创建:WebService接口
import javax.jws.WebMethod;@javax.jws.WebServicepublic interface WebService {@WebMethodString sayHello(String name);}
创建:WebServiceImpl实现类
import com.jixing.test.webService.WebService;import javax.jws.WebParam;@javax.jws.WebServicepublic class WebServiceImpl implements WebService {@Overridepublic String sayHello(@WebParam(name="name") String name) {return name+"helloWebService~";}}
创建:主启动类
import com.jixing.test.webService.impl.WebServiceImpl;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import javax.xml.ws.Endpoint;@SpringBootApplicationpublic class TestApplication {public static void main(String[] args) {SpringApplication.run(Te1bdfbstApplication.class, args);//发布服务String url = "http://localhost:9988/wsbServeice";Endpoint.publish(url,new WebServiceImpl());System.out.println("发布webService成功!");}}
SoapUI工具访问WebService接口
1.File>New SOAP Project
2.Project Name:自定义项目名称
Initial WSDL:访问的wsdl地址
Create Requests:勾选,自动生成请求报文
3.SoapUI发送请求
Postman工具访问WebService接口
1.请求头添加:Content-Type:text/xml
2.Postman发送请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://impl.webService.test.jixing.com/"><soapenv:Header/><soapenv:Body><impl:sayHello><!--Optional:--><name>?</name></impl:sayHello></soapenv:Body></soapenv:Envelope>