14

I just built a asp.net 2.0 web site. Now I need add REST web service so I can communicate with another web application. I've worked with 2 SOAP web service project before, but have no experise with REST at all. I guess only a coupleweeks would works fine. after googling, I found it's not that easy.

This is what I found:

There is NO REST out of box of asp.net.

WCF REST Starter Kit Codeplex Preview 2 base on .net 3.5 and still in beta

Rest ASP.NET Example

REST Web Services in ASP.NET 2.0 (C#)

Exyus

Handling POST and PUT methods with Lullaby

ADO.NET Data Service

...

Now my question,

a) Is a REST solution for .net 2.0? if yes, which one is best solution?

b) if I have to, how hard to migrate my asp.net from 2.0 to 3.5? is it as simple as just compile, or I have to change a lot code?

c) WCF REST Starter Kit is good enough to use in production?

d) Do I have to learn WCF first, then WCF REST Starter Kit? where is the best place to start?

I appreciate any help here.

Thanks Wes

3
  • Are those supposed to be links? Please fix, thx Commented Mar 27, 2009 at 19:30
  • 1
    What are you trying to do in a RESTful way that ASP.Net cannot do for you? Commented Mar 27, 2009 at 21:44
  • Thanks, DJ. I don't notice the link's lost and just put them back. Commented Mar 28, 2009 at 23:39

7 Answers 7

9

If your looking for a project that templates a REST service, you're correct in saying there is no out of the box solution. However, RESTful web services are possible using WCF. The key part is to use several attributes when defining your service functions that let the .NET framework know that the function is not expecting SOAP. The main attribute to use is the WebInvoke attribute.

Here is an example from developer.com:

[OperationContract]
[WebInvoke(Method = "PUT", UriTemplate = "/admin/post/{id}")]
void UpdatePost(string id, Post post);

The above code will actually be defined in an interface for your web service. The interface is created automatically when you create your WCF web service project. The actual code for the function will be placed in the class used to implement the web service.

Check out the article on developer.com for a full tutorial. It might seem overwhelming at first if your new to WCF, but after you dive into it, I'm sure you'll start to pick things up quickly. Here is the link for the artile: http://www.developer.com/net/article.php/10916_3695436_1

To answer all of your questions,

a) In .NET 2.0 you should be able to build RESTful services using WSE2.0, but if you have the option to use .NET 3.5, I would strongly recommend going the route of WCF since it is much easier and is designed with REST in mind.

b) Converting your project won't be hard at all. It's just a matter of targetting the new version of the framework in your project settings. Converting a web service from a WSE2.0 service to a WCF service will be a bit trickier though. The easiest way to do so would be to copy the code from each of the different web service functions into the class where you implement the new version of the function. Copy-Paste shinanigans :)

c) I'm not sure what this starter kit is that you're referring to. RESTful web services should be fully supported in WCF which was fully released as of 3.5

d) It would be helpful to understand WCF at least a little before beginning, but it's not crutial to understand it completely in order to get started. I would recommend just reading through the MSDN article on WCF at least once, and then begin working. I'm sure you will come across other questions as you begin, but you can look up those parts as you come across them.

Anyway, I hope this information helps. Good luck to you.

Edit

Some improvements have been made in the REST world. As Darrel Miller mentioned in the comments, WCF was not in fact built with REST in mind. I mis-spoke previously. In fact the framework is built with SOAP in mind and the WebInvoke attribute fills the gap. Although there is a lot of debate around the topic (Web API vs WCF REST), ASP.NET Web API is a new option for building REST services in .NET. I would strongly recommend that anyone who reads this post and is able to use .NET 4.5 in their project look into it as an option.

Sign up to request clarification or add additional context in comments.

3 Comments

I can assure you WCF was not built with REST in mind. The starter kit is an attempt to fill in the gaps that System.ServiceModel.Web left when they were trying to factor http back into the WCF abstraction that attempts to hide the underlying protocols.
I'm sure you are right. They probably have come a long way since the original RCs. I guess I just said that because every REST service I've built using WCF thus far has been fairly easy for me and seemed pretty natural...
The link developer.com/net/article.php/10916_3695436_1 now goes to a 2002 article on ODBC!
4

If you want a framework built with REST in mind, you should have a look at OpenRasta...

http://openrasta.org/

3 Comments

User base is less and less of a problem. Documentation is the focus of the next few weeks, so hopefully those issues will be addressed soon. Thanks for the feedback!
dead link. I don't even think this is a solution anymore
Still a solution and still maintained. Web site is dead while I move DNS hosts, will be back online sometime this week.
2

You could look at using ASP.NET MVC as a RESTful web services platform. WCF is probably the way to go in the long run, but MVC should easily handle it. Your actions would just need to be set up to return JSON or XML, depending on how you want to serialize it. MVC offers both a JsonResult and fully customizable ContentResult -- i.e., you serialize your response to a string property on the result and set it's type and encoding.

NOTE: MVC does require 3.5 SP1 so it's not going to be a 2.0 solution. If you require 2.0, you'll need to look elsewhere.

1 Comment

I was going to suggest the same (MVC) for an easy short term and WCF in the long run. Since "Upgrading" 2.0 projects to 3.5sp1 is trivial (as per my experience.)
1

Use WCF REST.

You can use it today. The WCF REST library is ready to go, usable in production.

The WCF Starter Kit (see http://msdn.microsoft.com/en-us/netframework/cc950529.aspx) is something else. It delivers extra stuff; it includes a set of VS project templates, docs, samples and a few tools for building REST apps (client or server) with WCF. One cool tool is the "Paste Xml as Type" command add-in to Visual Studio.

On the other hand, building a REST client, in the general case, I'd recommend taking advantage of the HttpClient assembly in the starter kit (Microsoft.Http.dll). It's small, simple, and useful. A low-risk and high-value dependency even at the current "preview" status of the Starter Kit.

If you were consuming just a single REST service, then you don't need the general Microsoft.Http.dll assembly; you can do all the stuff it does in some code that uses WebRequest. But if you wanted a more general flexible class for manipulating client-side REST requests, then grab that Microsoft.Http.dll.

2 Comments

from where I can grab that dll? (link)
It is part of the WCF REST Starter kit, or it was, 1 year ago. the current link for the starter kit is: msdn.microsoft.com/en-us/netframework/cc950529.aspx
0

I'm not sure about a REST solution for 2.0. So I think WCF is going to be the way you'll have to go with this one. MSDN has a long introduction to it.

My personal philosophy is that if a technology is still in beta then I would rather not use it for something that will potentially be a production application so I would start with WCF since it was introduced in the 3.0 version of the framework.

3.0 and 3.5 is actually an update to the libraries, but the CLR is still 2.0 so if the libraries you're using are not deprecated or changed in the new frameworks it should be okay.

Comments

0

Take a look at this CodeProject for a starting point. It seems somewhat... hacky. Modernizing to WCF would be cleaner.

Comments

0

REST, or RESTFUL Adding this to the System.Web in web.config will enable http get, and put.. aka REST-Like... but not full rest.

<System.Web>
  <webServices>
            <protocols>
                <add name="HttpSoap"/>
                <add name="HttpPost"/>
                <add name="HttpGet"/>
            </protocols>
        </webServices>
</System.Web>

1 Comment

This would be a start, but you'd need to add the code to respond to those requests, too. And a framework for organizing that code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.