How to insert and get .NET web-service data Object to My Android App

淺唱寂寞╮ 提交于 2019-12-12 00:15:44

问题


I have a web-service in .NET it's inserting and retrieving data's from database as object's.. I'll copy some part of web-service here..

   [WebMethod(Description = "This is used to insert details into sql server")]

    public string InsertDetails(DataTable myDetails, string STR1)
    {
        try
        {
            foreach (DataRow row in myDetails.Rows)
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "dbo.InsertQry";
                cmd.Parameters.Add(new SqlParameter("@P_no", row["POD_Number"].ToString()));
                cmd.Parameters.Add(new SqlParameter("@P_id", STR1));
                cmd.Parameters.Add(new SqlParameter("@P_author", Convert.ToInt64(row["P_author"])));

                //opening the connection
                cmd.Connection = sqlCon;
                sqlCon.Open();
                int retValue = cmd.ExecuteNonQuery();
                sqlCon.Close();
                if (retValue == 0)
                    return "false";
            }
            return "true";
        }

        catch (Exception ex)
        {
            ErrorLogger(ex);
            return "false";
        }
    }

//-----------------------------------------------------------------------------------
[WebMethod(Description = "This is used to get details from sql server")]

    public DataSet GetDetails(string STR1)
    {
        DataSet ds = new DataSet();
        try
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "dbo.SelectQryFromDB";
            //opening the connection
            cmd.Connection = sqlCon;
            sqlCon.Open();
            ds.DataSetName = "myTbl";
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds,"myTbl");
            sqlCon.Close();
            return ds;
        }

        catch (Exception ex)
        {
            ErrorLogger(ex);
            ds.DataSetName = "Error";
            return ds;
        }
    }

//----------------------------

Any-one Help me by providing me the details how can i send those data's and retrieve data's in Android..This is my first application so i don't know much?? Please Provide me details so that i can insert and get data's using web-service??

I heard of kSOAP2 and i'm trying to accomplish this by using kSOAP2..


回答1:


Working in Ksoap can be challenging sometimes. You first need to make sure your webservice is working fine and is giving you the proper result.

If that's done then you can consume the same from Android using ksoap library.

Here are few links that will help solve your problem:

1) How to call a local web service from Android mobile application will help you understand how you need to make a Ksoap call.

2) Inserting data into remote database from Android via ksoap

3) Returning data from server to Android



来源:https://stackoverflow.com/questions/12893638/how-to-insert-and-get-net-web-service-data-object-to-my-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!