Possible to create REST web service with ASP.NET 2.0 - web-services

Is it possible to create a REST web service using ASP.NET 2.0? The articles and blog entries I am finding all seem to indicate that ASP.NET 3.5 with WCF is required to create REST web services with ASP.NET.
If it is possible to create REST web services in ASP.NET 2.0 can you provide an example.
Thanks!

I have actually created a REST web service with asp.net 2.0. Its really no different than creating a web page.
When I did it, I really didn't have much time to research how to do it with an asmx file so I did it in a standard aspx file. I know thier is extra overhead by doing it this way but as a first revision it was fine.
protected void PageLoad(object sender, EventArgs e)
{
using (XmlWriter xm = XmlWriter.Create(Response.OutputStream, GetXmlSettings()))
{
//do your stuff
xm.Flush();
}
}
/// <summary>
/// Create Xml Settings object to properly format the output of the xml doc.
/// </summary>
private static XmlWriterSettings GetXmlSettings()
{
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
xmlSettings.IndentChars = " ";
return xmlSettings;
}
That should be enough to get you started, I will try and post more later.
Also if you need basic authentication for your web service it can be done, but it needs to be done manually if you aren't using active directory.

It is definitely possible to create RESTful web services using ASP.NET. If you are starting a new project I would definitely look into creating RESTful web services using WCF. The 3.5 .NET Framework allows you to specify RESTful endpoint along with a regular old SOAP endpoint and still deliver the same service.
All you really have to do is enable an endpointbehavior that calls out <webHttp />
Here is a good series on creating RESTful web services using WCF:
http://blogs.msdn.com/bags/archive/2008/08/05/rest-in-wcf-blog-series-index.aspx

You can certainly create RESTful web services in ASP.NET 2.0, for example, but there are no high-level APIs to do all the donkey work for you, as provided by WCF in .NET 3.5.

Well, of course you could always implement the spec yourself. It's just that there's nothing built-in to support it. If you use Nathan Lee's solution, do it as an http handler (.ashx) rather than an aspx. You can just about copy/paste his code into a new handler file.

You can do RESTful web services easily by implementing the spec using IHTTPHandlers.

Also check out using ASP.Net MVC. I've written some articles on this at my blog:
http://shouldersofgiants.co.uk/Blog/
Look for my Creating a RESTful Web Service Using ASP.Net MVC series

I'm only just beginning to use them, but from what I've seen 2.0 pretty assumes SOAP.

You can create RESTful service using
1) WCF REST service
2) ASP.NET Web API
If you all care about RESTful service, ASP.NET web api is that you should go with. But if you need service that supports both SOAP webservice and RESTful then WCF REST would be a good choice.
There are some articles that discuss about one versus another. This article may be helpful.

Related

Using servlets to implement REST web services in Java [duplicate]

This question already has answers here:
Servlet vs RESTful
(3 answers)
Closed 6 years ago.
I have created many REST web services providing JSON before using PHP and NodeJS and I know the concept.
Now I want to re-implement those web services using Java instead. After doing some research for how to implement web services in Java, I found some standards or libraries like JAX-RS, Spring or Jersey. However I not know the difference between all of them.
I wonder why we do not make a simple servlet which will be called through HTTP request and returns the result in the JSON format. And if I wanted to use one of these standards, what would be the best choice to implement web services that accepts HTTP requests and returns JSON?
You can use a stone to drive a nail into the wall. For sure you can. But why would you do that if you have a hammer available? Using the proper tool will make your life a lot easier.
In a similar way, you can create REST applications using only the Servlet API. However, there are other APIs that are designed to create REST applications. So, why don't you use them?
JAX-RS and Jersey
JAX-RS, currently defined by the JSR 339, is the standard Java API for creating RESTful web services and it's built the top of the Servlet API.
It's important mention that JAX-RS is an specification. In order to use it, you will need an implementation, such as Jersey, which is the reference implementation.
A few resources that may be useful:
JAX-RS 2.0 specification
Jersey documentation
Spring Framework
The Spring Framework allows you to create RESTful web services and it can be easly integrated with other Spring projects.
A few resources that may be useful:
Spring Framework website
Spring Framework documentation
Guide to build a RESTful web service with Spring Framework.
Other resources you may consider useful
Why use a framework for RESTful services in Java instead of vanilla servlets
Why use JAX-RS / Jersey?
Spring 4 vs Jersey for REST web services
Difference between JAX-RS and Spring Rest
You can do it using Servlet API actually. But you won't get all the benefits of JAX-RS like url mapping, parameters injection, ... You would have to write all this "by hand".
By the way, the difference between JAX-RS and Jersey is that JAX-RS is a specification, a standard and Jersey is an implementation of that standard. There are other implementations as well (RestEASY for example). Spring also has a module for REST services.

If I can write HTTP Service in WCF, why should I use Web API?

I've gone over other WCF vs Web API question as well as blogs. It is possible to write HTTP service with webHttpBinding in WCF too. So why should one move to Web API when it is possible to use WCF for the same purpose. Some say it's easy to use HTTP in Web API. But in what sense.
A lot of blogs make me confused. Most of them are like " You can do HTTP in WCF but Web API is pure REST based. You can use Web API if you want but you can use WCF too". It's like salesman describing their product which is really confusing for me here.
I have old asmx service which I want to move to REST Service. I tried WCF with webHttpBinding. It works well but why should one move to Web API?
If you already have a WCF service that you're satisfied with, then you're done. No need for WebAPI.
You would use WebAPI if there are features of the WebAPI which WCF cannot conveniently supply. The WebAPI is "closer to HTTP", whereas WCF is a generic communications framework.

Strategy to develop a web service in JAX WS

i'd like your help to designing a wb serice but I don't know how i can't do this.
In fact my application handles data management clients. My application is developped in struts 1.0, spring, weblogic and build-in maven.
He was asked to me to make an evolution because an external application need to access data such as displaying the address of the client or displaying data bank. For this, it was planned to create a web service to retrieve in real time.
I would like to know the strategy to use for designing a web service. Do I need to create a new Dynamite projet maven + JAX WS to my web service and deploy my war on my weblogic server?
Or they have something else to do ?
Thanks a lot !
I am not sure that this question is related to maven.
Adding a WebService (or RestService) could be quite easy with springframework and apache cxf (http://cxf.apache.org/)
see jaxws or jaxrs for more.
create web service in a two types but real time applications using jax-ws web services reason for consumer want to send data into provider.consumer can know the entire information about the provider by seeing its WSDL Document.

Approaches for creating REST Web services?

i am new to REST Service development. I compared the development mechanism for both REST and WS web services and i found that you can create a WS web service using WSDL file that is the top down appraoch (Correct me if i am wrong) and using bottom up approach also, that is generating the classes manually.
But when it comes to REST web service development you have to follow bottom up approach only that is generating the classes manually. NetBeans IDE provides certain wizards for creating REST web service quickly from databases, entity classes and patterns.
I had also seen when you are developing web service in eclipse and you are using wizard in eclipse IDE, you can create a REST web service from WSDL file. I found this very strange. My question here is what are the approaches we can have for creating REST web services. Can we create REST web services using top-down and bottom up approached. If yes then please provide me details.
Thanks.
It is possible to describe a REST service using a contract. This is the intent of WADL and WSDL 2.0. WADL is specifically a REST contract, whereas WSDL 2.0 evolved from the original WSDL spec. to support all HTTP bindings. Since REST services rely on the use of HTTP methods and headers to exchange messages a WSDL 2.0 contract can work. There is a really good explanation here: http://ajaxonomy.com/2008/xml/web-services-part-2-wsdl-and-wadl
For development of REST services, I'm not sure if NetBeans, Eclipse or other tools specifically support automated REST service from WSDL generation. I would imagine that most are still intended for SOAP service creation. At this point I think WSDL 2.0 and WADL can be used to describe a REST service, but are not intended for automated generation of a REST service.
REST services are simple HTTP request/response,and therefore don't require complex stubs. In most cases it would probably take more time to write the WSDL describing the REST service, than it would take to write the REST service itself.

Is it possible for Spring RESTful services to privde a WADL or something similar?

Situation:
We are planning to build a set of new services a long side a set of old SOAP (Spring, apache CXF) web services. Our customers are used to being able to use ?wsdl to get a wsdl describing a service and the content it will accept/return.
I'm looking at providing the new services via spring controllers and RESTful urls. However not all of a request can be handled via a RESTful url, so we still need to have a payload request and responses. I'm looking at use #RequestBody and #ResponseBody and spring's Message Converters to auto(magically) handle both XML and JSON content. The idea being to let spring do as much of the heaving lifting as possible.
The problem:
I'm trying to figure out if it's possible given the REST/Message converter concept, to be able to provide a description of a service and it's request/response data in a similar fashion to the ?wsdl request. I understand that there are WADL documents that can be generated by some systems, but they appear to be a proposel and not fully accepted yet.
Does anyone know if spring can generate WADLs or something else that I can use to allow clients to query the RESTful services data structures?
SpringMVC doesn't support WADL auto generation, mostly because it doesn't use the JSR-311 standard REST API.
I have create a blog entry with a simple WADL generation Controller in java :
Tuxgalaxy Blog Entry.
But Tomasz Nurkiewicz also provide a WADL generation Controller in scala :
nurkiewicz Blog Entry.
You could use CXF JAX-RS for your REST services since you're already using it for SOAP (you can even expose the same service as SOAP and REST with CXF), and CXF gives you the WADL that you want by adding ?_wadl&_type=xml
The following code will work with Spring REST 4x and its based on the suggested code by tuxgalaxy provided on below https://jira.spring.io/browse/SPR-8705
http://javattitude.com/2014/05/26/wadl-generator-for-spring-rest/