客户端
1、项目右键选择webservice
2、
3、客户端解析wsdl文件
@Service
public class GwrzService {
public boolean addList(List<GetPositonInfoVO> list){
boolean result=false;
// 创建WebService客户端代理工厂
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// 注册webservice接口
factory.setServiceClass(KeyPositon.class);
// 配置webservice地址
factory.setAddress("https://dmstesth.1111.com/dms.web/services/KeyPositonSOAP?wsdl");
factory.setUsername("admin");
factory.setPassword("123");
// 获得接口对象
KeyPositon service = (KeyPositon) factory.create();
int res=service.getPositonInfo(list);
if(res>0){
result=true;
}
return result;
}
}
服务端
1、服务端配置文件代码如下
import com.joydo.gfk.dms.dmsInterface.DCSToElearningSoap;
import com.joydo.gfk.dms.dmsInterface.ThirdToELearningSoap;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
/**
* @creater yfc
* @date 2019/12/04 16:05:05
* @describle 配置文件,webservice的接口文件
*/
@Configuration
public class CxfConfig {
@Autowired
private DCSToElearningSoap dcsToElearningSoap;
@Autowired
private ThirdToELearningSoap thirdToELearningSoap;
@Bean
public ServletRegistrationBean wsServlet(){
return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
}
@Autowired
@Qualifier(Bus.DEFAULT_BUS_ID)
private SpringBus bus;
@Bean
public Endpoint endpoint3(){
EndpointImpl endpoint = new EndpointImpl(bus, dcsToElearningSoap);
endpoint.publish("/DCSToElearningSoap");
return endpoint;
}
@Bean
public Endpoint endpoint4(){
EndpointImpl endpoint = new EndpointImpl(bus, thirdToELearningSoap);
endpoint.publish("/ThirdToELearningSoap");
return endpoint;
}
}
2、服务端接口代码
/**
* @创建人 yfc
* @创建时间 2019-12-02 9:44
* @描述 创建服务端接口
*/
//暴露服务名称;命名空间,包名接口倒排
//@WebService(name="ThirdToELearning",targetNamespace = "http://dmsInterface.dms.gfk.joydo.com")
@WebService(name = "ThirdToELearningSoap", targetNamespace = "NvSetWebService")
public interface ThirdToELearningSoap {
@WebMethod(operationName = "SetUserInfo", action = "NvSetWebService/SetUserInfo")
@WebResult(name = "SetUserInfoResult", targetNamespace = "NvSetWebService")
@RequestWrapper(localName = "SetUserInfo", targetNamespace = "NvSetWebService", className = "com.joydo.gfk.dms.dmsInterface.SetUserInfo")
@ResponseWrapper(localName = "SetUserInfoResponse", targetNamespace = "NvSetWebService", className = "com.joydo.gfk.dms.dmsInterface.SetUserInfoResponse")
public String setUserInfo( @WebParam(name = "userName", targetNamespace = "NvSetWebService")
String userName,
@WebParam(name = "Password", targetNamespace = "NvSetWebService")
String password,
@WebParam(name = "userList", targetNamespace = "NvSetWebService")
ArrayOfNvUser userList);
}