Best way to Consume Web services in iphone - iphone

I am creating iphone application which will require data from .NET web services.
I want to ask which type of web service is better for iphone (soap or restful)?
And my .Net project is built in mvc ...what type of web services are created for MVC.project.
Thanks

SOAP is too heavy for mobile - it will unnecessarily slow down your application with no added value.
Create a RESTful service instead.
If you want to make it part of your MVC application, then you will want to create a new controller and view, have it accept the parameters you need to identify the data you'd like returned, then use the "JSONResult" type to return JSON data.
I highly recommend you watch this video from www.asp.net. It demonstrates almost exactly what you want to do. The only difference is that instead of calling the controller from another page in your applicaiton, simply call it from your iPhone app.
http://www.asp.net/mvc/videos/how-do-i-return-json-formatted-data-for-an-ajax-call-in-an-aspnet-mvc-web-application
<>

Related

Real time use of REST web service in web application

I am new to REST and watched few videos and read few blogs on REST webservice and I came to know that generally people are using REST for supporting multiple devices like mobile and computer etc.
Now consider I am developing order management system and I want to support both computer as well as tablets. If in m traditional web application, I am using Spring MVC at front end, how REST will fit here so that it will support both the kind of devices.
One more doubt is, whatever examples I have browsed, it return html or json data. I want to develop the application the way spring MVC or struts works like returning name of jsp and jsp will be rendered with dynamic data (instead of returning string represented html).
I hope my question is clear. Please bear me as my questions are vague but I am looking from implementation and design point of view.
Just to start REST isn't anything to do with supporting mobile browsers. It is the architecture pattern HTTP follows. The Web had been REST since the early days.
I'm guessing what you mean is a server that returns light weight JSON that the client renders into HTML rather than the server returning HTML directly to browser. To do that you can use a java script framework that expects JSON data and that has a template engine to generate HTML on the fly in the browser. I think Anglar and Ember work like this.
Though I would only do this if you need to, and you don't need to do this just to support mobile browsers, you can support mobile just by making sure your CSS is responsive.

Cocoa library to interact with any web service API

Is there a general Cocoa or Cocoa Touch library for interacting with any web service API, or one which can be used as a basis for creating my own library for a web service? For example, I could add some details about how to interact with the Vimeo API (how to verify user details, what URLs to call). I'm not sure how this would work in reality.
If not, can anyone suggest an web service library which I could alter to change the API calls? It would need to be fairly simple (a small API) and easy to adapt. An example is this Cocoa library for Twitter (although it would probably be too complicated to adapt). Would it be easier just to code it up from scratch?
I don't think there is a library that will automagically work with any web API. In fact I don't even think it's possible to write such a library, since you can define your web API any way you want to. That library would have to be pretty smart in order to figure out how to use an arbitrary API.
I think the closest you'll get is something like ASIHTTPRequest, which is a great library for interacting with web services. If you add a JSON and/or XML parser you'll have everything you need to interact with almost any web API.
Found another library for interacting with RESTful web services. It's called RestKit. From their description:
RestKit is a Cocoa framework for interacting with RESTful web services in Objective C on iOS and Mac OS X. It provides a set of primitives for interacting with web services wrapping GET, POST, PUT and DELETE HTTP verbs behind a clean, simple interface. RestKit also provides a system for modeling remote resources by mapping them from JSON (or XML) payloads back into local domain objects. Object mapping functions with normal NSObject derived classes with properties. There is also an object mapping implementation included that provides a Core Data backed store for persisting objects loaded from the web.

iPhone app and server communication

We have a web-based BI reporting product. We have exposed certain webservices which mainly return html content and do authentication.
We are in a initial process of developing an iPhone App, which will interact with these services and get data on iPhone.
There are couple of things we need to make sure before we start with the actual development process...
1) Should we use SOAP or REST (Will have to write the server part in Java) for the communication between iPhone and our web-application?
2) If we use SOAP, Can you suggest something, which will effectively create web services stubs in Objective-C.
3) In either case (SOAP or REST), what security mechanism is suggested by Apple?
We want to know your thoughts on the best and effective way communication could be done between iPhone app and backend servers (mostly written in Java)
Thanks in advance.
If it is an option, I'd use REST
Never did it, but may this will help: http://abhicodehelp.blogspot.com/2010/12/handling-soap-with-iphone.html
I'd do any HTTP-Communication using ASIHttpRequest. It is SSL-capable
In my apps I use simple URL requests returning XML / Cocoa-touch plists over https. I guess that's called "REST" -- it's simple and quick to implement. There are long flame-fests over SOAP vs. REST -- I just use this technique and get my apps done :)

how to convert my vb app to an activex web service

I made an app in VB that I want to turn into a web service. I've been told I can create a web service from VB.NET but how? Can I convert my app into a ASP.NET app or do I have to re-write it? Can I turn my app into an Active X control and create a active x web service?
It's probably good to first try to understand exactly what you want and why you need it. A web service has little to do with ActiveX or ASP.NET technologies. It is a way to call methods of your libraries using SOAP or REST (or similar) requests. Once you know what for you need it, you can decide how to set it up.
You can use all the code you currently have but only if it was designed to be used with a library in mind. That means: no interactive forms, messageboxes etc. There are other restrictions, but let's not get ahead of ourselves too much.
To get from A to B, change your code such that it compiles as a DLL lib that you can use and call from other applications. From there to a web service is then only a small step away.

What common backend can be accessed securely from an iPhone and Android application?

I'm thinking about creating an application for the iPhone and Android that will need to access a common backend to retrieve account information. Can both access a web service over https? What other way would allow me to have one interface to the backend that is accessible by both?
They both work over http and https which is a common enough protocol. I would suggest you go with a RESTful web service so you expose your service via URI's like http://www.myservice.com/weather/zip/98007 which would return an XML blob that can be parsed by the client.
if you are starting from nothing, i'd definitely go with RESTful service that returns/accepts JSON... there are plenty of libraries for both platforms that will accept JSON and turn it into arrays and dictionaries.
I'd recommend using a RESTful web service backend, which is all standard HTTP and/or HTTPS. If you can use Ruby on Rails, its default scaffolding will get you about 99% of the way there and for the iPhone there is an open source project called ObjectiveResource that will automate your communication with this Rails backend. I haven't investigated yet what options are available on Android but since it is all simple HTTP it should be straightforward. I am not the maintainer of ObjectiveResource but I have contributed some code. You can check it out here:
http://iphoneonrails.com
One good approach I have seen used with other services is to write the backend in such a way that it can feed data back in different types - for Android an XML response is best, but for the iPhone sending back plist data is preferred (though it can also work with XML if required). In both cases it's easier to simply POST updates back to the server than to wrap an update in XML.
Both platforms should be able to use whatever form of authentication you wish to use, the iPhone I know supports all methods of HTTP authentication.