hjavaher
hjavaher

Reputation: 2609

Need to develop a RESTful API (both JSON and XML)

I'm looking to make a RESTful API on ASP.NET for a website. My problem is that I need it to be integrated into the website and not as a separate project.

I understand that WCF makes this really easy and its the ideal way to do it, but I don't think you can combine a WCF Service Project and a ASP.Net Website, Is this correct?

Is there a way we can do this using a webservice (asmx) file (since I know that asmx services use SOAP no?)

The reason I need this to be in the same project is that the customer will be able to purchase ssl for their domain (which the website is going to use) and I need to make the API secure as well, but the customer should not be asked to purchase two ssl or even a wildcard one. Knowing this, is there a better easier way of doing this using WCF?

Upvotes: 2

Views: 1208

Answers (4)

Esteban Araya
Esteban Araya

Reputation: 29654

I'd actually use NancyFX. Setting up routes is super-easy, and it comes with built in XML and JSON serializers that act based on the data in the headers.

Upvotes: 1

bloudraak
bloudraak

Reputation: 6002

I have an ASP.NET MVC 3 application that exposes both WCF REST services. I'm using .NET 4. You'll have to pay attention to how you configure your routing. For example, my WCF services are prefixed with something like "api/v1/" while all other requests are handled by ASP.NET MVC 3.

I had a problem because IIS refused to serve some "localhost" requests (like when your MVC 3 controllers try to consume your WCF rest services). That was solved by adding an entry to my hosts file. Also be aware of this when implementing an OAuth 2.0 Resource Server or Authorization Server.

Using WCF for REST services works ok in .NET 4, but the JSON serialization sucks big time. There are issues with default dates and it is rather slow. You may want to look at using a different serializer. With WCF you sacrifice some flexibility for some features you get for free.

ASP.NET MVC 4 (and the WEBAPI) is still in BETA, so I'd avoid that for a project with a short term release date.

Upvotes: 1

Cheeso
Cheeso

Reputation: 192417

You can use ASPNET MVC to build an API along with your website.

See How can I implement a site with ASP.NET MVC without using Visual Studio? for some details on building a basic MVC site.

ASPNET MVC services can respond in JSON or XML, or both.

There will be no special requirement for two SSL certs.

Upvotes: 1

mrdc
mrdc

Reputation: 716

Take a look at the new MVC4 Beta, it's set to go live sometime between March and April this year and should be able to accommodate your requirement to build a RESTful web service alongside a web application. I haven't spent too much time with MVC4 to go into the details, but it's definitely worth a look. Links: Get MVC4; MVC4 and WebAPI blog.

Hope this helps!

Upvotes: 2

Related Questions