objective-c 如何在iphone目标c中使用webservice?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1497222/
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-03 22:17:09  来源:igfitidea点击:

How to use webservice in iphone objective c?

iphoneobjective-cweb-services

提问by PeyloW

I need great video tutorial for using webservices in iphone objective c.My requirment is already values are in webservice, so just i want to access the webservice and validate username and password and return back to true or false get value display on the iphone.

我需要很棒的视频教程来在 iphone 中使用 webservices 目标 c.我的要求是值已经在 webservice 中,所以我只想访问 webservice 并验证用户名和密码并返回到真或假获取值显示在 iphone 上。

If anybody have idea about tutorial please help me out..

如果有人对教程有想法,请帮助我..

回答by PeyloW

The by far easiest way to consume a web service on an iPhone is to use Hessian. Implement the server in Java using the official Hessian distribution, or in .NET using HessianC#.

迄今为止,在 iPhone 上使用 Web 服务的最简单方法是使用Hessian。使用官方 Hessian 发行版在 Java 中实现服务器,或使用HessianC#在 .NET 中实现服务器。

Let us assume you have defined the following interface for your web service, and implemented it as a HessianServlet(Just replace a HttpServlet):

让我们假设您已经为您的 Web 服务定义了以下接口,并将其实现为 a HessianServlet(只需替换 a HttpServlet):

public interface MyService {
  public String doWithStuff(String action, Object stuff);
}

It is just as easy on .NET.

在 .NET 上同样简单。

On the client side use HessianKit, where you create proxies to the web service, and then use them just as if they where local object. First you must conbert the Java interface above to an Objective-C protocol.

在客户端使用HessianKit,您可以在其中创建 Web 服务的代理,然后像使用本地对象一样使用它们。首先,您必须将上面的 Java 接口转换为 Objective-C 协议。

@protocol MySertvice
-(NSString)do:(NSString*)action withStuff:(id)stuff;
@end

Then use it as a proxy, just as if it was a local object:

然后将其用作代理,就像它是本地对象一样:

id<MyService> proxy = [CWHessianConnection proxyWithURL:serviceURL
                                               protocol:@protocol(MyService)];
NSLog(@"%@", [proxy do:@"Something" withStuff:arguments]);

Hessian in a binary web service protocol, meaning allotsmaller payloads, which is good on a slow GSM connection. Hessian is also much easier to encode and decode, compared to XML and JSON, meaning your app can make calls and receive responses using less CPU, and memory for temporary objects.

二进制网络服务协议中的 Hessian,意味着分配较小的有效载荷,这在慢速 GSM 连接上很好。与 XML 和 JSON 相比,Hessian 也更容易编码和解码,这意味着您的应用程序可以使用更少的 CPU 和临时对象的内存来进行调用和接收响应。

回答by Felixyz

iPhone on Railsis

iPhone on Rails

an Objective-C port of Ruby on Rails' ActiveResource.

Ruby on Rails 的 ActiveResource 的 Objective-C 端口。

but it can be used as a wrapper to access any RESTful webservice. ObjC classes and objects correspond to ActiveRecord classes and objects (which correspond to data base tables and rows).

但它可以用作包装器来访问任何 RESTful web 服务。ObjC 类和对象对应于 ActiveRecord 类和对象(对应于数据库表和行)。

There's an introductory screencast over here.

这里有一个介绍截屏在这里