公司采用webservice+soap技术连通了web项目与app项目.这样使得调试app项目变得很方便,业务逻辑全部放在web上,app管理用户审批查阅等功能.app采用mui+springboot前后端可分离可不分离.
主讲测试方法:
web接口方法,引包别引错了.
@WebService(name = "AppWebService", targetNamespace = "http://AppWebinterfaceImp.appWebService.com/")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface AppWebService {
/** 登录接口*/
@WebMethod
public String userLogin(String username,String password);
实现类略
app端用的是service+qname 的方式实现连接的.虽然架构很老,可用起来还是很爽的.
正常远程调用webservice要根据wsdl文档先生成本地代码,然后加到项目里.这里我直接把接口拷贝到一个测试类的包里即可.
public static void main(String[] args) throws Exception {
String wsdlUrl = "http://localhost:8080/ZLXT/mobile-interface?wsdl";
//QName,第一个参数是服务的命名空间,第二个参数是服务的名称
Service service = Service.create(new URL(wsdlUrl), new QName("http://AppWebinterfaceImp.appWebService.com", "appWebService"));
//QName,第一个参数是服务的命名空间,第二个参数是得到接口的Port
AppWebService port = service.getPort(new QName("http://AppWebinterfaceImp.appWebService.com","appWebServicePort"), AppWebService.class);
boolean ret = port.cusSeal("B20200519110259","","");
System.out.println(ret);
}
QName里的参数就是你发布的wsdl文档location代码里有说明.
说明:1.首先你要懂得如何发布wsdl服务,然后得到xxx?wsdl文档
2.我这项目是再struts框架下使用的,需要在配置文件中配置一个 项目访问入口
<wss:binding url="/mobile-interface">//入口
<wss:service>
<!-- bean的值需要加前缀 "#",studentWsService是实现类在bean容器中的名称 -->
<ws:service bean="#appWebServiceImpl">
</ws:service>
</wss:service>
</wss:binding>
3.之前接触到测试方法要么是框架写客户端要么用soap拼请求体请求头等,也搞不懂.用service+qname感觉方便多了