建类
抽象类
先写好业务代码,再写一个webService抽象类,这个抽象类需要些注释声明一些东西
@WebService声明这是一个web service,targetNamespace 是之后调用方法时寻址的,可以自定义,建议按http://按包名顺序倒着写,name和实现类的serviceName保持一致
@WebMethod在抽象类里的方法上注明这是webService的方法,@WebParam打在入参上,否则等会传不进来值
实现类
写此抽象类的实现类
endpointInterface写继承的抽象类的路径,serviceName自定义
在实现类里写一个主方法,运行这个实现类,端口只要不被占用就可以写,路径的最后名写serviceName,一定要加?wsdl
跑这个实现类,如下图就跑成功了,保持这个服务不要关闭
测试
我整理出两种测试方法,一是java测试,二postman测试
java测试
postman测试
第一步
选择post测试方式,写入接口地址
第二步
新增一个参数,键为:Content-Type,值为:text/xml
第三步
选择raw格式,xml
红线画起来的是接口抽象类的@WebService里的targetNamespace
getNoticeListById是方法名,userId是参数,要写中文记得用<![CDATA[参数]]>
<?xml version="1.0" encoding="utf-8"?>
<soapevn:Envelope xmlns:soapevn="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="http://impl.webservice.mobile.service.learn.compliance.kmpro.cn/">
<soapevn:Body>
<test:getNoticeListById>
<userId>leo</userId>
</test:getNoticeListById>
</soapevn:Body>
</soapevn:Envelope>
Send提交,出结果