六月下起了大雪
2018-03-02 03:03
采纳率: 100%
浏览 1.8k
已采纳

如何将soap请求返回的数据打印到控制台。急急急!!!!

提供的地址:http://127.0.0.1:3306/cqxyfw/lawenforcezunitappinfo/SOAP?wsdl
接口函数原型:getEmployeescorelistnewServiceApp(String empidnum);
通过身份证号查询数据。
附上代码,成功之后立即采纳

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • xiaodeng_1113 2018-03-06 02:05
    已采纳

    public class Test {

    public static void main(String[] args) {

    try {

    String endpoint = "http://127.0.0.1:3306cqxyfw/lawenforcezunitappinfo/SOAP";//直接引用远程的wsdl文件

    Service service = new Service();

    Call call = (Call) service.createCall();

    call.setTargetEndpointAddress(endpoint);

    call.setOperationName(new QName("getEmployeescorelistnewServiceApp"));// WSDL里面描述的接口名称

    call.addParameter("empidnum",org.apache.axis.encoding.XMLType.XSD_STRING,
    javax.xml.rpc.ParameterMode.IN);// 接口的参数

    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
    String result = (String) call.invoke(new Object[]{"身份证"}); // 给方法传递参数,并且调用方法

    System.out.println("返回数据:" + result);

    } catch (Exception e) {

    System.err.println(e.toString());

    //e.printStackTrace();
    }

    }

    }

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 六月下起了大雪 2018-03-02 03:06

    图片说明

    评论
    解决 无用
    打赏 举报
  • 六月下起了大雪 2018-03-02 03:06

    图片说明

    评论
    解决 无用
    打赏 举报
  • a718089112 2018-03-02 03:16

    尝试一下试试,原理就是用HttpURLConnection 模拟浏览器post请求获取数据

     public String getResult() {
            String result = "";
            String targetURL = "http://127.0.0.1:3306/cqxyfw/lawenforcezunitappinfo";
            try {
                URL targetUrl = new URL(targetURL);
                HttpURLConnection httpConnection = (HttpURLConnection) targetUrl.openConnection();
                httpConnection.setDoOutput(true);
                httpConnection.setRequestMethod("POST");
                httpConnection.setRequestProperty("Content-Type","application/json");
    
                OutputStream outputStream = httpConnection.getOutputStream();
                outputStream.write(input.getBytes());
                outputStream.flush();
                if (httpConnection.getResponseCode() != 200) {
                    throw new RuntimeException("Failed : HTTP error code : " + httpConnection.getResponseCode());
                }
                StringBuffer output = new StringBuffer();
                InputStream is = httpConnection.getInputStream();
                byte[] bytes = new byte[is.available()];
                int size = 0;
                while ((size = is.read(bytes)) != -1) {
                    String str = new String(bytes, 0, size, "UTF-8");
                    output.append(str);
                }
                result = output.toString();
                is.close();
                httpConnection.disconnect();
                outputStream.close();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }
    
    评论
    解决 无用
    打赏 举报
  • Java流浪者 2018-03-02 05:33

    http://blog.csdn.net/u012009613/article/details/52014113 看看这个能帮到你吗,webservice调用
    百度的时候用 代码语言+wsdl+soap

    评论
    解决 无用
    打赏 举报
  • 西吉哥 2018-03-02 06:42
     public string get(string Url, string postDataStr)
            {
                HttpWebResponse response = null;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (string.IsNullOrEmpty(postDataStr) ? "" : "?") +     postDataStr);
                request.Timeout = 30000; // 设置超时时间,单位毫秒。
                try
                {
                request.Method = "GET";
                request.ContentType = "text/html;charset=UTF-8";
    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
                response = (HttpWebResponse)request.GetResponse();
    
                Stream myResponseStream = response.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                string retString = myStreamReader.ReadToEnd();
    
                      myStreamReader.Close();
     myStreamReader.Dispose();
                      myResponseStream.Close();
                      myResponseStream.Dispose();
    
                      return retString ;
                } catch(Exception ex){
                    Console.WriteLine(ex.ToString());
                } finally{
                    if (response != null)
    {
    response.Close();
    }
                }
                return "false";
            }
    

    取方法返回值打印出来就行了

    评论
    解决 无用
    打赏 举报
  • Powerful_Current 2018-03-02 06:46

    1.首先新建一个空的项目,打开cmd,,cd到这个项目的src目录下,
    2.使用wsdl2java生成客户端调用代码,命令:wsdl2java -d . http://127.0.0.1:3306/cqxyfw/lawenforcezunitappinfo/SOAP?wsdl
    3.将这些代码连同包copy到项目中,
    4.在applicationContext.xml中配置

    <jaxws:client id="wsdlClient" address=" http://127.0.0.1:3306/cqxyfw/lawenforcezunitappinfo/SOAP?wsdl"

    serviceClass="com.xx.xxx.XxxInterface">

    /jaxws:client

    5.建立test类
    public class ClientTest {
    
        private ApplicationContext applicationContext;
    
        @Before
        public void before() {
    
            applicationContext = new ClassPathXmlApplicationContext(
                    "applicationContext.xml");
    
        }
    
        @Test
        public void testCxfSpringClient() {
            // 从spring容器中取出porttype
            XxxInterface xxxInterface = (XxxInterface) applicationContext
                    .getBean("wsdlClient");
    
            // 调用portType的方法
            List list = xxxInterface.getEmployeescorelistnewServiceApp(String empidnum);
    //循环list并打印
            for () {
    
            }
        }
    
    }
    
    
    
    
    
    
    
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题