制作网络服务

时间:2014-11-13 08:19:35

标签: java web-services oracle-adf

我编写了以下Java代码来编写一个Web服务,它将从数据库表中返回一些行:

package ncw;

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.ArrayList;

import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class PLSQLWS {
    @WebMethod
    @Oneway
    public ArrayList getSalesPlanningTestData() {
        String query = "select * from sales_planning_test_data";
        ArrayList data = new ArrayList();
        try {
            Connection conn = connect();
            if (conn != null) {
                PreparedStatement stmt =  conn.prepareStatement(query);
                ResultSet rs = stmt.executeQuery();
                while (rs.next()) {
                    SALES_PLANNING_WS_DATA row = new SALES_PLANNING_WS_DATA();
                    row.setId(rs.getInt(1));
                    row.setPoNumber(rs.getString(2));
                    row.setSomethingElse(rs.getString(3));
                    row.setFlag(rs.getString(4));
                    data.add(row);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return data;
    }

    public ArrayList<String> getNames(){
        ArrayList<String> list = new ArrayList<String>();
        list.add("usman");
        list.add("Mohsin");
        return list;
    }

    private Connection connect() throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection connection =
            DriverManager.getConnection("jdbc:oracle:thin:@192.xxx.x.xxx:1531:mysid", "username","password");
        return connection;
    }
}

SALES_PLANNING_WS_DATA.java

package ncw;



public class SALES_PLANNING_WS_DATA {
    private int id;
    private String poNumber;
    private String somethingElse;
    private String flag;

    public SALES_PLANNING_WS_DATA() {

    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setPoNumber(String poNumber) {
        this.poNumber = poNumber;
    }

    public String getPoNumber() {
        return poNumber;
    }


    public void setSomethingElse(String somethingElse) {
        this.somethingElse = somethingElse;
    }

    public String getSomethingElse() {
        return somethingElse;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }


    public String getFlag() {
        return flag;
    }
    public String toString(){
        return getPoNumber();
    }
}

我使用JDeveloper创建webservice。当我在HTTP Analyzer中测试它并调用getSalesPlanningTestData()方法时,我没有得到任何结果。输出部分显示“所选消息不是肥皂消息”。当我调用getNames()方法时,它会返回数据。

有人知道这里有什么问题吗?

1 个答案:

答案 0 :(得分:1)

删除@Oneway注释。它定义了webmethod没有返回任何数据