【发布时间】:2014-01-20 09:03:48
【问题描述】:
我正在使用 SOAP 方法使用 Asp.NET Webservice 从 Android 应用程序中的 SQL 数据库中检索数据。
我也见过 JSON 方法,但它使用的是 php。
哪种方法最好???我有 Windows Server 和 SQL 数据库,所以我将只使用 Asp.NET Web 服务。
【问题讨论】:
标签: android asp.net sql web-services
我正在使用 SOAP 方法使用 Asp.NET Webservice 从 Android 应用程序中的 SQL 数据库中检索数据。
我也见过 JSON 方法,但它使用的是 php。
哪种方法最好???我有 Windows Server 和 SQL 数据库,所以我将只使用 Asp.NET Web 服务。
【问题讨论】:
标签: android asp.net sql web-services
如果你有 SqlServer 意味着你可以选择 asp.Net Json Webservices 。 Json 很容易解析,我自己也只使用 json 格式的 .net 网络服务。
解析对移动开发者来说既快速又简单
public class Employee
{
public string Name { get; set; }
public string Company { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public string Country { get; set; }
}
然后在 Webserice 中添加以下方法。
Json Array-Object大部分我们会使用
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GenerateTopicListToJSon()
{
try
{
//Do ur query in GetMethod() to retrieve from DB
List<Employee> lstEmployee = GetMethod();
var topic = from t in lstEmployee
select new
{
Name= t.TopicID,
Company = t.Company,
Address = t.Address,
Phone = t.Phone,
Country = t.Country
};
var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
return oSerializer.Serialize(topic);
}
希望对你有帮助..
干杯。
【讨论】: