飙车老猫 2019-03-28 15:47 采纳率: 100%
浏览 460
已采纳

java调用C#发布的wsdlwebservice

我使用soapui调用是正常的,但是使用java调用后一直报错,不知道问题出现在哪里

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.jfree.util.Log;

public class TestPost {


    /**
     * @param args
     */
    public static void main(String[] args) {


        StringBuffer sb = new StringBuffer();
        sb.append("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\">");
        sb.append("<soap:Header>");
        sb.append("<a:To s:mustUnderstand=\"1\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">http://localhost:8899/SmatPrintService</a:To>");
        sb.append("</soap:Header>");
        sb.append("<soap:Body>");
        sb.append("<tem:PrintLabel>");
        sb.append("<tem:pagecount>1</tem:pagecount>");
        sb.append("<tem:printname>Send To OneNote 2016</tem:printname>");
        sb.append("<tem:labelpath>C:\\workspace\\MLSMESClientProject1\\labs\\aaa.btw</tem:labelpath>");
        sb.append("<tem:dicy>aa:123456</tem:dicy>");
        sb.append("</tem:PrintLabel>");
        sb.append("</soap:Body>");
        sb.append("</soap:Envelope>");

        System.out.println(sb.toString());
        String address = "http://desktop-8mf1qs2:8899/SmatPrintService?wsdl";

        try {
            URL u = new URL(address);
            HttpURLConnection uc = (HttpURLConnection) u.openConnection();
            uc.setDoOutput(true);
            uc.setRequestProperty("Content-Type",
                    "application/soap+xml;charset=utf-8");
            uc.setRequestProperty("Charset", "UTF-8");
            uc.setRequestMethod("GET");
            uc.setDoOutput(true);
            uc.setDoInput(true);
            OutputStreamWriter osw = new OutputStreamWriter(uc
                    .getOutputStream(), "UTF-8");
            osw.write(sb.toString());
            osw.flush();
            osw.close();

            BufferedReader rd = new BufferedReader(new InputStreamReader(uc
                    .getInputStream(), "UTF-8"));
            StringBuffer sbuffer = new StringBuffer();
            int ch;
            while ((ch = rd.read()) > -1) {
                sbuffer.append((char) ch);
            }
            String rec_string = sbuffer.toString().trim();
            System.out.println("返回数据:" + rec_string);
            rd.close();

        } catch (MalformedURLException e) {
            Log.error(e.getMessage());
        } catch (IOException e) {
            Log.error(e.getMessage());
            System.out.println(e.getMessage());
        }
    }

}

报错如下:

Server returned HTTP response code: 500 for URL: http://desktop-8mf1qs2:8899/SmatPrintService?wsdl
  • 写回答

1条回答 默认 最新

  • 红橡树 2019-03-28 18:47
    关注

    500就是内部错误了,假设你调用的接口以前就是正常的只是你调用报错,那么检查下你的请求方式和请求参数是否符合接口的要求。如果你的请求方式和请求参数都没有问题,那么就是那个接口的问题,可能的话可以看下这个接口的日志

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制