Pregunta

I have to consume some web methods in Java but I made the mistake to return Datasets instead of another type which has made the code less interoperable. Here is an example of a webmethod that i want to consume:

 [WebMethod (Description =" Returns all employees")]
public DataSet GetAllEmployees()
{
    RefreshConnection();
    SqlDataAdapter sql = new SqlDataAdapter("select * " +
        " from Employee_Table", OpenConnection());
    DataSet employeeDataSet = new DataSet();
    sql.Fill(employeeDataSet, "Employees");
    return employeeDataSet;
}

Now I don't know how to get rid of this problem. I'm a beginner in web services so please give also an explanation of your solution.

¿Fue útil?

Solución

I think I solved the problem by converting the result of sqlDataReader to a List with strings.

[WebMethod (Description =" Returns all employees")]
public List<string> GetAllEmployees()
{
    RefreshConnection();
   List <string> data = new List<string>();
    SqlCommand sqlData = new SqlCommand("select * " +
      " from Employee_Table", OpenConnection());
      SqlDataReader sqlReads = sqlData.ExecuteReader();
      while (sqlReads.Read())
      {

          data.Add((string)sqlReads.GetValue(1));
          data.Add((string)sqlReads.GetValue(2));


      }
      return data;
}

And in java by the proxy object:

private List<String> getEmployee() throws RemoteException{
        return Arrays.asList(proxy.convertToList());
    }

Now my problem is how to differ between two columns?The array takes all in without formatting the result as it would be by using a resultSet.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top