我还是新的asp.net,和我目前正在创建一个Web服务,将让以显示它从我的SQL数据库中的数据在android应用程序中。获取数据集以JSON而不是XML的ASP.NET Web服务
我现在能够得到我从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,可能我建议你看看网页API。您使用的网络服务技术已过时。如果你需要的只是json,那么就使用web api。 – Don
@Don你能不能请您给一些链接,我可以看看你有什么建议(我知道这是过时,但我的教授坚持用这种方式,因为这是他习惯的方式) – 96ASP43
@ 96ASP43它是一个小的错字检查更新代码'foreach(DataColumn col in dsvrs.Columns){' – haraman