KSoap2 或 Android 的 RESTful Web 服务
在 Android 中处理 Web 服务的最佳方式是什么? 我一直在研究 KSoap2 库和 RESTful Web 服务。
我得到了一个与 KSoap2 一起使用的工具,但仅当 Web 服务位于远程服务器上时,而不是本地主机上。我尝试重定向传入和传出的端口,正如 android 开发网站上所说,我使用了我所在网络的 ip、我自己的 ip 和 localhost-ip (它在网站上说不能使用本地主机,因为这是模拟器自己的环回网络。
对于 RESTful Web 服务,我只尝试过使用 google 应用程序引擎作为服务器的教程,如果我理解正确的话,将 RESTful Web 服务连接到是否很容易。我的应用程序中需要有一个数据库连接,哪个数据库连接通常与 REST 一起使用?
抱歉,这个问题很困惑,我已经尝试了很多天来整理替代方案,但我越看越困惑。 !
预先感谢您的帮助 /AK
What is the best way to deal with web services in Android?
I have been looking at KSoap2 library and RESTful web services.
I got one working with KSoap2, but only when the web service is on a remote server, not on localhost. I have tried to redirect the ports for incoming and outgoing as it says on the android dev site, i have used the ip of the network i am on, my own ip and the localhost-ip (it says on the site that one cannot use localhost cause that is the emulators own loop-back network. None works.
With RESTful webservices, i have only tried a tutorial where a google app engine is used as server if i understood it right. Is it easy to connect a RESTful web service to a database. I need to have a database connection in my applikation, which one is normally used with REST?
Sorry for the confused question, it's been many days of trying to sort just the alternatives out, and the more I look the confused I get.
THanks in advance for any help!
/AK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我肯定会去休息。您还可以使用 JSON 而不是 XML。 Android 内置了对 JSon 和 REST 的支持,通过 JAX-RS 规范变得非常易于使用和维护。
正如 Maks 所提到的,这也是一种轻量级方法。
如果您有更复杂的场景,您可以使用一些 JSon 库,例如 GSon,用于 java 对象和 JSon 之间的 JSon 解析器。
另外,如果您决定在服务器端使用 Seam,我建议您使用 RestEasy。
[]s
I would go for REST for sure. You could also use JSon instead of XML. Android has a built in support for JSon and REST becames quite easy to use and maintain with JAX-RS specification.
It is also as mentioned by Maks a light weigth approach.
If you have a more complex scenario you could use some JSon librarie like GSon for JSon parser between java objects and JSon.
Also if you decide to go for Seam in the server side I would suggest you to use RestEasy.
[]s
要连接到与 Android 模拟器在同一台计算机上运行的网络服务器,您需要使用 IP 地址 10.0.2.2
请参阅此处:
在模拟器中成功连接应用程序后到在同一台计算机上运行的网络服务器,然后您可以决定如何最好地在它们之间发送数据。如果您选择使用 XML 和/或 SOAP,那么 kSoap2 是您的最佳选择。使用 RESTful Web 服务更加“轻量级”,仅指您的应用程序使用普通的 HTTP 和 url 来获取/发送数据到您的 Web 服务器上运行的应用程序。
To connect to a webserver running on the same machine as your android emulator you need to use the IP address 10.0.2.2
see here:
Once you have your app in the emulator connecting successfully to a webserver running on the same machine you can then decide how best to send data between the two of them. If you choose to use XML and/or SOAP then kSoap2 is your best bet. Using a RESTful webservice is much more "light weight" and just refers to using normal HTTP and urls for your app to get/send data to the app running on your webserver.
将 Android 连接到 RESTful Web 服务时,请检查本手册:连接Android 上的 RESTful Web 服务
check this Manual, when connecting Android to RESTful Web Services: Connecting RESTful Web Services on Android