如何从 xcode 项目发布网络服务请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4668134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:04:48  来源:igfitidea点击:

How to post a webservice request from an xcode project

web-servicesxcode

提问by humblePilgrim

I'm trying to generate a web service call from my iphone app.

我正在尝试从我的 iphone 应用程序生成网络服务调用。

I'm working with web services for the the first time.

我是第一次使用网络服务。

I realize that an SOAP request would something like this:

我意识到一个 SOAP 请求是这样的:

My actual web service is not on local.

我的实际 Web 服务不在本地。

POST /MyFirstWebService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance>
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org
/soap/envelope/">

<soap:Body>
<HelloWorld xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>

POST /MyFirstWebService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
内容长度:长度
SOAPAction:“ http://tempuri.org/HelloWorld

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance>
xmlns:xsd="http:/ /www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org
/soap/envelope/">

<soap:Body>
<HelloWorld xmlns="http://tempuri.org/ " />
</soap:Body>
</soap:Envelope>



I want the string hello world returned from the web service.

我想要从 Web 服务返回的字符串 hello world。

What is the best way to do this?

做这个的最好方式是什么?

I have also read about a framework called JSON.

我还阅读了一个名为 JSON 的框架。

Can that be useful here?

这在这里有用吗?

回答by Mihir Mehta

This link provides simple explaination of how to consume web service in iphone it also explains simple post simple Get and SOAP

此链接提供了有关如何在 iphone 中使用 Web 服务的简单说明,它还解释了简单的 Post simple Get 和 SOAP

Consuming Web Services in iPhone Applications

在 iPhone 应用程序中使用 Web 服务

Difference Between Soap and REST

肥皂和 REST 之间的区别

SOAP and RESTful web services have a very different philosophy from each other. SOAP is really a protocol for XML-based distributed computing, whereas REST adheres much more closely to a bare metal, web-based design. SOAP by itself is not that complex; it can get complex, however, when it is used with its numerous extensions (guilt by association).

SOAP 和 RESTful Web 服务的理念非常不同。SOAP 实际上是一种用于基于 XML 的分布式计算的协议,而 REST 更接近于基于 Web 的裸机设计。SOAP 本身并没有那么复杂;然而,当它与其众多的扩展一起使用时,它会变得复杂(因联想而感到内疚)。

To summarize their strengths and weaknesses:

总结一下他们的长处和短处:

* SOAP *

* 肥皂 *

Pros:

优点:

Langauge, platform, and transport agnostic Designed to handle distributed computing environments Is the prevailing standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors Built-in error handling (faults) Extensibility

与语言、平台和传输无关 设计用于处理分布式计算环境 是 Web 服务的主流标准,因此可以更好地支持其他标准(WSDL、WS-*)和供应商提供的工具 内置错误处理(故障) 可扩展性

Cons:

缺点:

Conceptually more difficult, more "heavy-weight" than REST More verbose Harder to develop, requires tools

概念上比 REST 更难,更“重量级”更冗长更难开发,需要工具

* REST *

* 休息 *

Pros:

优点:

Language and platform agnostic Much simpler to develop than SOAP Small learning curve, less reliance on tools Concise, no need for additional messaging layer Closer in design and philosophy to the Web

与语言和平台无关 开发比 SOAP 简单得多 学习曲线小,对工具的依赖更少 简洁,不需要额外的消息传递层 更接近 Web 的设计和理念

Cons:

缺点:

Assumes a point-to-point communication model--not usable for distributed computing environment where message may go through one or more intermediaries Lack of standards support for security, policy, reliable messaging, etc., so services that have more sophisticated requirements are harder to develop ("roll your own") Tied to the HTTP transport model

假设点对点通信模型——不适用于消息可能通过一个或多个中介的分布式计算环境缺乏对安全、策略、可靠消息等的标准支持,因此具有更复杂要求的服务更难开发(“自己动手”)绑定到 HTTP 传输模型