81,092
社区成员
发帖
与我相关
我的任务
分享
// 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();
}
}
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);
}
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 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());