使用WSDL在Android ListView中实现

时间:2012-06-30 15:03:25

标签: android json web-services soap jax-ws

我尝试从使用JAX-WS,WSDL构建的Web Service获取数据,我想在Android ListView中实现。

这是我在Netbeans上构建的Web服务代码。

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package in.figures.on.mobile;

import db.koneksi.dbKoneksi;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.json.simple.JSONValue;

/**
 *
 * @author Setyadi
 */
@WebService()
public class AksesData {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Lokasiku")
    public String Lokasiku(
            @WebParam(name = "lon") String lon,
            @WebParam(name = "lat") String lat) {
        //TODO write your implementation code here:

        dbKoneksi con = new dbKoneksi();
        Statement statement;
        String sql = "SELECT desa "
                + "FROM dki "
                + "WHERE ST_Within(ST_SetSRID(ST_MakePoint("+lon+","+lat+"),0),geom);";
        ResultSet hasil;
        String desa = null;

        try{
            statement = con.getConnection().createStatement();
            hasil = statement.executeQuery(sql);
            hasil.next();
            desa = hasil.getString(1);
        }
        catch(Exception e){
            desa = "desa_thegagals";
        }
        finally{

        }

        if (con != null)  {
            return desa;
        }
        else  {
            return "lokasiku_thegagals";
        }
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Kategori")
    public String Kategori() {
        //TODO write your implementation code here:

        dbKoneksi con = new dbKoneksi();
        Statement statement;
        Properties properties;
        List list = new ArrayList();
        String sql = "SELECT kategori FROM kategori ";
        ResultSet hasil;
        String kategori = null;

        try{
            statement = con.getConnection().createStatement();
            hasil = statement.executeQuery(sql);
            while (hasil.next()) {
                properties = new Properties();
                properties.put("kategori", hasil.getString(1));
                list.add(properties);
            }
            kategori = JSONValue.toJSONString(list);
        }
        catch(Exception e){
        }

        return kategori;
    }

}

有人想帮助我,至少给我一个关于此的教程。 提前致谢

2 个答案:

答案 0 :(得分:2)

Android不提供对SOAP Web服务的任何支持。他们更喜欢我们使用XML或JSON的RESTful Web服务。但是有一些SOAP库。 KSOAP很受欢迎,我个人也遇到过问题。 http://ksoap2.sourceforge.net/

另一个建议是icesoap。它是一个非常简单的库,使用和理解,它对我来说就像一个魅力。 http://code.google.com/p/icesoap/

答案 1 :(得分:0)

用于2D数组中的返回数据 只需获取数据并将其转换为String。 然后将其存储在Array

rs = s.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
colCount = rsmd.getColumnCount();
String[][] result;
result = new String[size][rsmd.getColumnCount()];

int j=0;
            while(rs.next()) 
            {

                for (int i = 1; i <= colCount; i++) 
                {

                    Object value=null;
                if(!rsmd.getColumnTypeName(i).matches("varchar"))
                {
                    if(rsmd.getColumnTypeName(i).matches("decimal"))
                        value=(Object)rs.getDouble(i);
                    else
                        value=(Object)rs.getObject(i);
                }
                    else
                    {
                        value = (Object)rs.getString(i);
                    }
                    if(value!=null)
                    {
                        result[j][i-1]=value.toString();
                    }
                    else
                    {
                        result[j][i-1]="--";
                    }
                }j++;
            }
        }
        catch (SQLException | ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

并且在Android手机玩具中需要获取该数组并将其转换为适当的数据类型。

如果您要显示它,那么您可以按原样显示。无需转换为原始数据类型。

相关问题