Consuming ASP .NET web services in iOS part1

Since, at the time of my writing, iOS SDK does not natively support SOAP WebServices many have found different ways to consume these web services. Some of them include manually making HTTP requests and parsing response, using WSDL to ObjectiveC generators and more. One of the convenient ways I found when it comes to RPC is to combine the niceness of ASP .NET with JSON-RPC which can be accessed in iOS easily. So, let’s begin creating an iOS friendly ASP .NET web service.

The framework which makes this possible is Jayrock. Jayrock is a modest and an open source (LGPL) implementation of JSON and JSON-RPC for the Microsoft .NET Framework, including ASP.NET.

Let’s see how we can make this work. First, let’s create a simple HelloWorld() web service. Open up Visual Studio and create ASP .NET web project (or any other suitable type).

Visual Studio New Web Application Dialog

Create New Application

Add a generic handler to your app and call it whatever you like.

Visual Studio Add Handler

Add generic handler

Now we need to reference Jayrock library, so right click your project and “Add Reference”, browse to find Jayrock.dll and Jayrock.Json.dll and add references to them. Once you’ve finished that, we can continue to build our web service.

Open the handler you’ve created and modify the class to look something like this:

[csharp]public class my_service : Jayrock.JsonRpc.Web.JsonRpcHandler
{
	[Jayrock.JsonRpc.JsonRpcMethod("HelloWorld")]
	public string HelloWorld()
	{
		return "Hi iOS, this is ASP.NET!";
	}
}[/csharp]

  And now we’re ready. Try out this service in your browser, you should be able to see its description and test page. You can also test to see if it actually works, like this.
Jayrock RPC page

Jayrock RPC

If you see this, we’re completed JSON RPC web service in C# ASP .NET. In the next part of this blog, we’ll create an iOS app which will consume this service. Stay tuned!

5 thoughts on “Consuming ASP .NET web services in iOS part1

  1. Pingback: Consuming ASP .NET web services in iOS part 2 | Development

  2. Pingback: Call a web service - iPhone Dev SDK Forum

  3. Pingback: iPhone App and ASP.Net Web Service - iPhone Dev SDK Forum

  4. Pingback: Returning objects with Jayrock (.NET) | SeekPHP.com

  5. Pingback: Returning objects with Jayrock (.NET) | trouble86.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>