-2
我是網絡服務新手,我試圖以Json格式保存數據,下面是我的service.asmx文件的代碼,在這裏我從數據庫中獲取數據,但我不知道如何以Json格式保存數據。請指導我解決這個問題。Webservice將數據保存爲Json格式
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data.Sql;
using System.Data.SqlClient;
namespace JSONWeb
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[ScriptService]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public DataSet SelectData()
{
SqlConnection con = new SqlConnection("Data Source=HOME;database=Data;Integrated Security=true");
SqlCommand cmd = null;
SqlDataAdapter da;
DataSet ds = new DataSet();
try
{
con.Open();
cmd = new SqlCommand("SelectData", con);
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
return ds;
}
}
}