【发布时间】:2016-01-15 17:06:08
【问题描述】:
我还是 asp.net 的新手,我目前正在尝试创建一个 Web 服务,该服务将从我的 SQL 数据库中获取数据,以便在 android 应用程序中显示它。
我现在能够从 SQL 过程(获取客户信息)中获取我想要的数据,并且响应是 XML 格式的。
我搜索了很多关于一个很好的教程,该教程展示了如何在没有运气的情况下以 JSON 而不是 XML 获取响应(我还尝试了一些关于堆栈溢出的答案),但关于数据集的内容却很少。
这是我到目前为止的代码,任何帮助将不胜感激。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
namespace ART
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
SqlCommand cmdselect = null, cmdinserted;
SqlConnection con4, converiler, con3, con;
SqlDataAdapter da4, da, da3;
SqlDataReader dr;
[WebMethod]
public DataSet AboneKullanici(int pkAbone)
{
SqlConnection conFriends = new SqlConnection("Data Source=.;Initial Catalog=TTL;Integrated Security=True;");
DataSet dsvrs = new DataSet();
cmdselect = new SqlCommand();
cmdselect.CommandText = "spAboneKullanici";
cmdselect.CommandTimeout = 0;
cmdselect.CommandType = CommandType.StoredProcedure;
cmdselect.Connection = conFriends;
da = new SqlDataAdapter(cmdselect);
cmdselect.Parameters.Add("@aboneid", SqlDbType.Int, 10).Value = pkAbone;
conFriends.Open();
da.Fill(dsvrs, "kullaniclar");
conFriends.Close();
return dsvrs;
}
}
}
【问题讨论】:
标签: asp.net json web-services datatable webmethod