Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I begin for making a RESTful web service based on the .NET framework?

Tags:

rest

c#

.net

I am creating an iOS application that I need to connect to a database through a web service. I only know basic knowledge about using RESTful web services, I have never written my own before and was wondering if you can give me any advice on where I can find out how to write my own RESTful web service.

In my iOS program I will be sending a part number to the web service the web service will then need to return color and size information on the part. I'm not sure if XML is the best format or is there something better?

I guess my question is twofold here:

  1. Is this something I should be doing with a RESTful web service?
  2. Where can I find tutorials on creating a .NET-based RESTful web service?
like image 690
ios85 Avatar asked Nov 29 '11 14:11

ios85


1 Answers

You can use WCF for creating RESTful services, and you could use Nancy:

I'd recomend using json as a data format see here for some excelent links: iPhone/iOS JSON parsing tutorial

in wcf you'd go about creating a service like this: see here for a reasonable example: http://blogs.msdn.com/b/kaevans/archive/2008/04/03/creating-restful-services-using-wcf.aspx

[ServiceContract]
public interface IServeStuff
{
    [OperationContract]
    [WebGet(UriTemplate = "/stuff/{id}", 
            ResponseFormat = WebMessageFormat.Json)]
    Stuff GetStuff(string id);
}

public class StuffService : IServeStuff
{
    public Stuff GetStuff(string id)
    {
         return new Stuff(id);
    }
}

Or with nancy http://www.nancyfx.org/ like this:

public MyModule : NancyModule
{
    public MyModule()
    {  
        Get["/stuff/{id}"] = parameters => {
            return new Stuff(parameters.id).AsJson();
        };
    }
}

But before all this listen to @PeterKelly because he's right

like image 58
albertjan Avatar answered Nov 14 '22 23:11

albertjan