什么类型的Web服务最适合iOS? [英] What type of webservice works best with iOS?

查看:73
本文介绍了什么类型的Web服务最适合iOS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将为iPhone和iPad创建一个内部应用程序,用于跟踪销售电话,相关报价,照片和这些报价的图纸。我还处于概念设计阶段,我正在尝试阅读我的应用程序和Web服务之间的不同通信方式。显然,因为这将主要用于3G或...边缘我想要一个有效的协议,所以我的直觉反应是远离基于XML的事情,如XML-RPC或SOAP。我想在服务器上使用PHP和MySQL,并计划在iOS上使用Core Data。

I'm going to be creating an internal app for the iPhone and iPad that will keep track of sales calls, the associated quotes, photos, and drawings for those quotes. I'm still in the concept design phase and I'm trying to read up on the different ways to communicate between my app and the webservice. Obviously since this will be used mostly over 3G or ... Edge I want an efficient protocol so my gut reaction is to stay away from XML based things like XML-RPC, or SOAP. I would like to use PHP and MySQL on the server and plan on using Core Data on iOS.

所以我有几个具体的问题:

So I have a couple specific questions:


  1. 我应该使用什么方案来提高性能?

  2. 我应该使用什么方案来方便在服务器上使用?

  3. 为了便于在iOS上使用,我应该使用哪种方案?

  4. 考虑整个项目,我应该采用什么方案?

  5. 尽管有网络开销,但是更好地使用基于XML的方案?为什么?

  1. What scheme should I use for performance?
  2. What scheme should I use for ease of working with on the server?
  3. What scheme should I use for ease of working with on iOS?
  4. What scheme should I use considering the project as a whole?
  5. Is using an XML based scheme better despite the network overhead? Why?


推荐答案

鉴于您提出多个问题的方式,您可能会发现最终的问题您使用的解决方案将是竞争目标之间的平衡行为。

Given the way you've asked multiple questions you probably realize that the ultimate solution you use will be a balancing act between competing goals.

1:您需要更好地定义性能。我假设你指的是网络传输时间,这意味着保持服务器延迟低和传输的字节数低。最终可能是定制的二进制线协议,其也被分析用于适当的压缩性和压缩(例如重复的串或序列)。这种协议的缺点是在服务器和服务器上编码可能会更加困难。客户端,因为您将无法使用SDK支持标准化编码,除非精心设计的二进制协议往往是脆弱的,以支持您的应用程序的未来更改和扩展。

1: You need to define "performance" better. I'm assuming you're referring to network transmission time which means keeping server latency low and number of bytes transmitted low. The ultimate is probably a custom binary wire protocol that's also been analyzed for compressibility and compression applied where appropriate (e.g. repeated strings or sequences). The downside to such a protocol is that it will likely be more difficult to code on both server & client since you won't be able to use SDK support for standardized encodings, and unless thoughtfully designed binary protocols tend to be brittle for supporting future changes and extensions to your application.

此外,你应该考虑如何定义你的协议的交易,即使你的协议需要多次往返而你的协议需要很多往返,你仍然会很慢。

Also you should consider how you define the transactions of your protocol, even with an efficient encoding if your protocol requires many round trips vs. a single round trip you'll still be slow.

最后,根据您发送的数据的大小,与数据大小相比,编码的开销可能并不重要。

Lastly depending on the size of the data you're sending, the overhead of an encoding may be immaterial compared to the size of the data.

我推荐坚持使用标准化的编码格式,可以使用库支持进行解析,从而将字段缩小为两个主要语法:XML或JSON。

I recommend sticking with a standardized encoding format which can be parsed with library support, which narrows the field to two major grammars: XML or JSON.

2:XML和JSON都很好在服务器框架中受支持。使用XML服务时,我建议使用REST样式模式,因为它们通常很容易构建,并且您不必将应用程序与其他人的风格相符。

2: XML and JSON both are well supported in server frameworks. When using XML services I recommend a REST style pattern as they're usually easy to build and you don't have to conform your application to somebody else's style.

我会远离基于SOAP的Web服务,即使构建它们可能得到很好的支持(特别是在Windows平台上),因为在移动客户端上执行完整的基于SOAP的解析的复杂性很高,并且在那里得不到很好的支持。我没有发现WSDL编译器自动生成的对象序列化在编码时节省了大量的时间,通常很容易序列化为REST样式的XML,或者甚至更简单的JSON。

I would stay away from SOAP-based web services even though building them may be well supported (especially on Windows platforms), because the complexity of doing a full SOAP-based parse on the mobile client is high and not well supported there. I don't find automatically generated object serialization by WSDL compilers to be that big of a win for saving time when coding, it is usually pretty easy to serialize to a REST-style XML or often even simpler for JSON.

3:iOS支持内置的SAX样式XML解析器,并且有各种类库可用于支持具有不同功能和速度级别的内存中DOM实现。选择最适合您需求的产品。我个人更喜欢TBXML,它快速,相当轻量级,并且易于编程,但由于它不验证模式并且它是内存中的树,因此在某些情况下它是不合适的。 这是一场枪战 iOS XML库性能。

3: iOS supports a built-in SAX style XML parser, and there a variety of class libraries available that support in-memory DOM implementations with different features and speed levels. Pick the one best for your needs. I personally prefer TBXML which is fast, fairly lightweight, and easy to program to, but because it does not validate schemas and it is an in-memory tree, it is not appropriate in some situations. Here is a shootout of iOS XML library performance.

如果您使用Google,可以使用几种适用于iOS的JSON库。或查看此答案

There are several JSON libraries available for iOS if you Google around. Or look in this answer.

SOAP不受支持且库选择有限。您始终可以手工解析服务器生成的SOAP响应,但它很容易发生服务器端更改,这些更改是合法的SOAP(例如,不同的名称空间前缀),可能会破坏硬编码的XML解析器。

SOAP is not well supported and there are limited library choices. You can always hand-parse the SOAP responses generated by a server but it is brittle to server-side changes that are legal SOAP (e.g. different namespace prefixes) that could break a hardcoded XML parser.

4:在不了解项目细节的情况下很难回答,但我倾向于使用JSON或简单的基于XML的编码,因为:两者通常很容易在客户端和服务器上编程,两者都可以完成在线上具有合理的效率,并且可能在未来的应用程序迭代中可扩展。

4: Difficult to answer without knowing more about your project's details, but I'd lean towards a JSON or simple XML-based encoding because: both are usually easy to program to on client and server, both can be done with reasonable efficiency on the wire, and are likely to be extensible for future app iterations.

JSON具有以下优点:解析起来更简单,可以减少冗长,以及也可以更容易为其他目的重新执行任务,例如在服务之上构建Ajax Web客户端。

JSON has advantages of being a bit simpler to parse, can be less wordy, and may also be easier to re-task for other purposes, such as building an Ajax web client on top of your services.

5:XML与JSON相比其他编码?我认为这是个人偏好。 XML可以比JSON更具自我描述性,但可能需要更多解析工作。 JSON可以降低原始字节的开销,并且易于解析。同样,编码开销可能很大,或者可以忽略不计,具体取决于内容的大小。您也可以在任何情况下应用外部压缩。

5: XML vs JSON vs. other encodings? I think this is a personal preference. XML can be more self-describing than JSON but is likely to be more work to parse. JSON can be lower overhead in raw bytes and is easy to parse. Again the encoding overhead may be significant or may be negligible depending on the size of your content. Also you can apply external compression in any case.

这篇关于什么类型的Web服务最适合iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆