【问题标题】:How can i made soap Request and Response in Java?如何在 Java 中制作肥皂请求和响应?
【发布时间】:2012-04-25 10:08:09
【问题描述】:

如何执行soap web服务以及如何打印数据?

目前我正在使用以下代码

package com.appulento.pack;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public class SimpleHTTPRequest
{
  public static void main(String[] args) throws Exception {
    final String url =
        "http://**********:8000/sap/bc/srt/rfc/sap/zmaterials_details/" +
          "800/zmaterials_details/zmaterials_details_bind",
      soapAction ="urn:sap-com:document:sap:soap:functions:mc-style/ZMATERIALS_DETAILS",
      envelope1="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"" +
          " xmlns:urn=\"urn:sap-com:document:sap:soap:functions:mc-style\">" +
        "<soapenv:Header>"+
        "<soapenv:Body>"+
        "<urn:ZMATERIALS_DETAILS>"+
        "<Language>D</Language>"+
        "<MaterialGroup>00208</MaterialGroup>"+
        "</urn:ZMATERIALS_DETAILS>"+
        "</soap:Body>"+
        "</soap:Envelope>" ;
    HttpURLConnection connection = null;
    try {
      final URL serverAddress = new URL("http://*********:8000/sap/bc/srt/wsdl/"+
          "srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/" +
          "document?sap-client=800&sap-user=************&sap-password=****");
      connection = (HttpURLConnection)serverAddress.openConnection();
      connection.setRequestProperty("SOAPAction", soapAction);
      connection.setRequestMethod("POST");
      connection.setDoOutput(true);
      final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
      writer.append(envelope1);
      writer.close();
      final BufferedReader rd =
          new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String line;
      while ((line = rd.readLine()) != null) System.out.println(line);
    } finally { connection.disconnect(); }
  }
}

我想发送 xml 作为输入请求,我也想在 xml 中显示。

【问题讨论】:

  • 您的代码看起来很棒。现在只需使用 POST 而不是 GET 并将您的请求实际写入输出。
  • 感谢您的回复我该如何处理回复
  • 据我所知,您已经在处理它了——写入 System.out。
  • 这里我只是在控制台中获取 WSDL
  • 请检查一下我的代码哪里出错了

标签: java web-services soap


【解决方案1】:

可以像您一样使用 httpConnection 发送 HTTP 请求并解析响应。 但它已经由其他人编写,使用wsimport 工具和-keep 选项。它将为您生成 Java 工件,以便使用 SOAP 发送请求。

【讨论】:

  • 我的代码中是否有任何错误,请查看一次并告诉我,以便我可以采取其他方式进行操作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-07
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 2019-06-23
相关资源
最近更新 更多