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

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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题