Springboot调用soap webservice(Client)

1.使用jdk自带的webservice工具wsimport生成相关类
  • 测试wsdl
    http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
wsimport -s d:\wsdl -p com.example.demo.request -encoding utf-8 http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl

-s 存储目录;
-p 包名;
-encoding 文件编码,默认会采用操作系统编码,中文为gbk,建议使用utf-8;

Springboot调用soap webservice(Client)_第1张图片

2.构建相关的配置类及测试方法
@Configuration
public class IpConfig {

    @Bean
    public IpAddressSearchWebServiceSoap webService(){
        return new IpAddressSearchWebService().getIpAddressSearchWebServiceSoap();
    }
}
@SpringBootApplication
@RestController
@RequestMapping("/soap")
public class DemoApplication {

    @Autowired
    private IpAddressSearchWebServiceSoap soap;

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @RequestMapping("/{ip}")
    public ArrayOfString searchIp(@PathVariable("ip") String ip) {
        ArrayOfString response = soap.getCountryCityByIp(ip);
        return response;
    }
}

这里写图片描述

你可能感兴趣的:(Spring,webservice)