检查一下WSDL文件吧 ,看看参数有没有对应起来..

解决方案 »

  1.   

    我用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());
      

  2.   


    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();
      

  3.   

    回复这么快。上次看你恢复别人的帖子这么获取的。借鉴了。 soap访问webservice,基本上都是这样的。呵呵,还有http get或post获取,都可以参考webservice提供的方法获取。
      

  4.   

    还有一张情况是用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); }
      

  5.   

    axis2不如axis1方便。没有规定必须axis2吧。
      

  6.   

    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();
    } }
      

  7.   

    我用了另外两种方式,一种是stub存根方式,楼上的方式昨天我也封装了一个方法,不过好像用serverclient方式有点小问题!