急等回复关于axis2参数无法传入 检查一下WSDL文件吧 ,看看参数有没有对应起来.. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用httpurlconnection获取过。String address = "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx"; URL url = new URL(address); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setDoOutput(true); http.setDoInput(true); http.setRequestMethod("POST"); http.setUseCaches(false); http.setRequestProperty("Content-Type", "text/xml"); http.connect(); DataOutputStream out = new DataOutputStream(http.getOutputStream()); String cityId = "-1"; String content = "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"><soap12:Body><getTVstationDataSet xmlns=\"http://WebXml.com.cn/\"><theAreaID>" + cityId + "</theAreaID></getTVstationDataSet></soap12:Body></soap12:Envelope>"; out.writeBytes(content); out.flush(); out.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(http .getInputStream())); String line; StringBuffer buffer = new StringBuffer(); while ((line = reader.readLine()) != null) { buffer.append(line); } reader.close(); http.disconnect(); System.out.println(buffer.toString()); String s = "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?op=getTVstationDataSet"; URL url = new URL(s); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setDoOutput(true); http.setDoInput(true); http.setRequestMethod("POST"); http.setUseCaches(false); http.setRequestProperty("Content-Type", "text/xml"); http.connect(); OutputStream out = http.getOutputStream(); String theAreaID = "16"; String content = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><getTVstationDataSet xmlns=\"http://WebXml.com.cn/\"><theAreaID>" + theAreaID + "</theAreaID></getTVstationDataSet></soap:Body></soap:Envelope>"; out.write(content.getBytes()); out.flush(); out.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(http .getInputStream())); String line; StringBuffer buffer = new StringBuffer(); while ((line = reader.readLine()) != null) { buffer.append(line); } reader.close(); http.disconnect(); 回复这么快。上次看你恢复别人的帖子这么获取的。借鉴了。 soap访问webservice,基本上都是这样的。呵呵,还有http get或post获取,都可以参考webservice提供的方法获取。 还有一张情况是用axis2,生成对应的java文件,然后自己就随便用了。public static void main(String[] args) { String[] s = new String[] { "-u", "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl", "-o", "client", "-S", "false", "-t" }; WSDL2Java.main(s); } axis2不如axis1方便。没有规定必须axis2吧。 axis2也是可以的,昨晚研究了下,可以的。不过不是用RPCServiceClient客户端了,而是ServiceClient了。// axis2方式 private static void axis2WebService() { try { String soapBindingAddress = "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl"; ServiceClient sender = new ServiceClient(); EndpointReference endpointReference = new EndpointReference( soapBindingAddress); Options options = new Options(); options.setAction("http://WebXml.com.cn/getTVstationDataSet"); options.setTo(endpointReference); sender.setOptions(options); OMFactory fac = OMAbstractFactory.getOMFactory(); // 这个和qname差不多,设置命名空间 OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", "getTVstationDataSet"); OMElement data = fac.createOMElement("getTVstationDataSet", omNs); // 对应参数的节点 String[] strs = new String[] { "theAreaID" }; // 参数值 String[] val = new String[] { "-4" }; for (int i = 0; i < strs.length; i++) { OMElement inner = fac.createOMElement(strs[i], omNs); inner.setText(val[i]); data.addChild(inner); } // 发送数据,返回结果 OMElement result = sender.sendReceive(data); System.out.println(result.toString()); } catch (AxisFault ex) { ex.printStackTrace(); } } 我用了另外两种方式,一种是stub存根方式,楼上的方式昨天我也封装了一个方法,不过好像用serverclient方式有点小问题! jacob操作word ,如何使导出的word 形式为页面视图? jsp内容监控,防止恶意修改 javascript 正则表达式 问题 15位或18位 怎么 写,在线等?谢谢 会php和java的进, 团队开发,怎么保护源码外泄 100分求助iReport报表高手,在线等! 用JAVA能否做出这样的程序: javabean传到jsp的疑问 ireport 大牛过来看看 图片模糊 js里alert()的问题 请问java有什么方便的函数可以画出这种jpg图? <input type="file"/> 自动在后面生成了 <input type="button" value="清空"> (如图)
URL url = new URL(address);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setDoOutput(true);
http.setDoInput(true);
http.setRequestMethod("POST");
http.setUseCaches(false);
http.setRequestProperty("Content-Type", "text/xml");
http.connect(); DataOutputStream out = new DataOutputStream(http.getOutputStream());
String cityId = "-1";
String content = "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"><soap12:Body><getTVstationDataSet xmlns=\"http://WebXml.com.cn/\"><theAreaID>"
+ cityId
+ "</theAreaID></getTVstationDataSet></soap12:Body></soap12:Envelope>";
out.writeBytes(content); out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(http
.getInputStream()));
String line;
StringBuffer buffer = new StringBuffer();
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
reader.close();
http.disconnect();
System.out.println(buffer.toString());
String s = "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?op=getTVstationDataSet";
URL url = new URL(s);
HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setDoOutput(true);
http.setDoInput(true);
http.setRequestMethod("POST");
http.setUseCaches(false);
http.setRequestProperty("Content-Type", "text/xml");
http.connect(); OutputStream out = http.getOutputStream();
String theAreaID = "16";
String content = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><getTVstationDataSet xmlns=\"http://WebXml.com.cn/\"><theAreaID>"
+ theAreaID
+ "</theAreaID></getTVstationDataSet></soap:Body></soap:Envelope>";
out.write(content.getBytes()); out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(http
.getInputStream()));
String line;
StringBuffer buffer = new StringBuffer();
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
reader.close();
http.disconnect();
String[] s = new String[] {
"-u",
"http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl",
"-o", "client", "-S", "false", "-t" };
WSDL2Java.main(s); }
// axis2方式
private static void axis2WebService() {
try {
String soapBindingAddress = "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx?wsdl";
ServiceClient sender = new ServiceClient();
EndpointReference endpointReference = new EndpointReference(
soapBindingAddress);
Options options = new Options();
options.setAction("http://WebXml.com.cn/getTVstationDataSet");
options.setTo(endpointReference);
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
// 这个和qname差不多,设置命名空间
OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/",
"getTVstationDataSet");
OMElement data = fac.createOMElement("getTVstationDataSet", omNs);
// 对应参数的节点
String[] strs = new String[] { "theAreaID" };
// 参数值
String[] val = new String[] { "-4" };
for (int i = 0; i < strs.length; i++) {
OMElement inner = fac.createOMElement(strs[i], omNs);
inner.setText(val[i]);
data.addChild(inner);
}
// 发送数据,返回结果
OMElement result = sender.sendReceive(data);
System.out.println(result.toString());
} catch (AxisFault ex) {
ex.printStackTrace();
} }