java调用webService接口

public static void main(String[] args) throws IOException {
	 URL wsUrl = new URL("http://ne.xxxx.net/services/NE8Service?wsdl");
     
     HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();
     
     conn.setDoInput(true);
     conn.setDoOutput(true);
     conn.setRequestMethod("POST");
     conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
     
     OutputStream os = conn.getOutputStream();
     
     //请求体
     String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://web.operation.ne.xxxx.com/\">"+
				   "<soapenv:Header/>"+
				   "<soapenv:Body>"+
				      "<web:callNE8LogicToString>"+
				        " <arg0>"+
				          "<ip>127.0.0.1</ip>" + 
				          "<loginPwd>xxxx</loginPwd>" + 
				           "<loginUser>xxxx</loginUser>" +
				            "<params>xxxxxx</params>"+
				            "<scanParams>xxxx</scanParams>"+
				            "<serverCode>xxxx</serverCode>"+
				            "<states>xxxx</states>"+
				         "</arg0>"+
				      "</web:callNE8LogicToString>"+
				   "</soapenv:Body>"+
				"</soapenv:Envelope>";
				    		 
     
     os.write(soap.getBytes());
     
     InputStream is = conn.getInputStream();
     
     byte[] b = new byte[1024];
     int len = 0;
     String s = "";
     while((len = is.read(b)) != -1){
         String ss = new String(b,0,len,"UTF-8");
         s += ss;
     }
     System.out.println(s);
     
     is.close();
     os.close();
     conn.disconnect();
}

相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页