【问题标题】:How to call SOAP service endpoint for RestTemplate如何为 RestTemplate 调用 SOAP 服务端点
【发布时间】:2019-01-30 17:07:32
【问题描述】:

这是我第一次一起使用 SOAP 和 spring。但是问题很多。不确定它的有效问题不是我的要求。

所以我在 SOAP 点上使用 xml 作为输入。这项服务运作良好。 现在我正在尝试调用服务方法,类似于下面的代码。

HttpHeaders header = new HttpHeaders();
        header.set(HttpHeaders.CONTENT_TYPE, "application/saop+xml");
        Resource resource = new ClassPathResource("soap/valid-req.xml");
        String xml = IOUtils.toString(resource.getInputStream(), "UTF-8");

        HttpEntity entity = new HttpEntity<>(xml, header);
        String response = restTemplate.postForObject("http://localhost:8080/ws/HttpImport", entity, String.class);

是否可以使用 spring Rest Template 调用 SOAP 服务,或者我们是否有其他替代方法。

有人可以帮忙吗?

提前致谢。

【问题讨论】:

标签: spring rest soap


【解决方案1】:

试试这个代码

HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.TEXT_XML);
Resource resource = new ClassPathResource("soap/valid-req.xml");
String xml = IOUtils.toString(resource.getInputStream(), "UTF-8");
HttpEntity entity = new HttpEntity<>(xml, header);
ResponseEntity<String> response = restTemplate.exchange("http://localhost:8080/ws/HttpImport", HttpMethod.POST, entity, String.class);
String responseString =response.getBody(); 

【讨论】:

  • 虽然此代码可能会解决问题,including an explanation 关于如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。
猜你喜欢
  • 1970-01-01
  • 2010-09-16
  • 1970-01-01
  • 2018-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多