简体   繁体   English

Android应用程式Web服务从MS SQL Server 2008提取资料

[英]android app webservice pull data from ms sql server 2008

I'm trying to figure out the best way to have my android app pull data from my ms sql server 2008 database. 我正在尝试找出让我的android应用从ms sql server 2008数据库提取数据的最佳方法。 I understand that there's two parts to this that the android app (written in java) has to call the web service (written in .net) and then that will call the database and pull the data, but all the examples I've found are rather piecemeal. 我了解到,Android应用程序(用Java编写)必须调用Web服务(用.net编写),这有两部分,然后它将调用数据库并提取数据,但是我发现的所有示例都是比较零碎。 They seem to only show the app side and not the webservice side or just the webservice side and not the other way around. 它们似乎只显示应用程序端,而不显示网络服务端,或者仅显示网络服务端,而不是相反。 I need one where I can see both sides and see how they work together. 我需要一个可以看到双方并了解他们如何合作的机构。 Does anyone have any good examples? 有人有很好的例子吗?

Some examples I've seen use a ksoap design that doesn't seem the best because it doesn't look like it's really supported that well. 我见过的一些示例使用的ksoap设计似乎并不是最好的,因为它看起来并没有得到真正的支持。 http://ksoap2.sourceforge.net/ http://ksoap2.sourceforge.net/

Another one I've seen is a Jersey based design http://jersey.java.net/ , which looks like it would be easier but I have no idea how to interface it with a .net web service. 我看到的另一个是基于Jersey的设计http://jersey.java.net/ ,它看起来会更简单,但是我不知道如何将其与.net Web服务接口。

With MS SQL Server, I assume you will be using ASP.NET? 使用MS SQL Server,我假设您将使用ASP.NET? If so, check out WCF Web HTTP Programming model (http://msdn.microsoft.com/en-us/netframework/cc950529.aspx). 如果是这样,请检查WCF Web HTTP编程模型(http://msdn.microsoft.com/zh-cn/netframework/cc950529.aspx)。 It's basically Microsoft's implementation of REST in WCF. 基本上,这是Microsoft在WCF中实现的REST。

For an example, let's say I want to retrieve a user info from the SQL database. 例如,假设我要从SQL数据库检索用户信息。 To do this, I can issue a normal HTTP GET request: 为此,我可以发出一个普通的HTTP GET请求:

GET http://server/service/userinfo/id/5

The above will request user info that has primary id of 5, the WCF layer will then translate this into an appropriate SQL query and return it in a JSON string: 上面的代码将请求主ID为5的用户信息,然后WCF层会将其转换为适当的SQL查询,并以JSON字符串返回:

{ name : "john doe", email : "john@doe.com", phone : "111-111-1111" }

Your app basically parse this JSON string and convert it into POJO. 您的应用程序基本上会解析此JSON字符串并将其转换为POJO。

I think this RESTful method is much easier to implement than the traditional SOAP method. 我认为这个RESTful方法比传统的SOAP方法更容易实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM