We already have a WCF API with basichttpbinding. Some of the calls have complex objects in both the response and request.
We need to add RESTful abilities to the API. at first I tried adding a webHttp endpoint, but I got
At most one body parameter can be serialized without wrapper elements
If I made it Wrapped it wasn't pure as I need it to be.
I got to read this, and this (which states "ASP.NET Web API is the new way to build RESTful service on .NET").
So my question is, should I make 2 APIs(2 different projects)? one for SOAP with WCF and one RESTful with ASP.NET Web API? is there anything wrong architecturally speaking with this approach?
-
What type of message formats are you looking for?hanzolo– hanzolo2012年08月27日 16:06:33 +00:00Commented Aug 27, 2012 at 16:06
-
What do you mean? Json or XML are fine by me...Mithir– Mithir2012年08月27日 19:16:27 +00:00Commented Aug 27, 2012 at 19:16
-
that's what I meant..hanzolo– hanzolo2012年08月27日 20:52:47 +00:00Commented Aug 27, 2012 at 20:52
-
There is also WCF Data Services, formerly ADO.NET Data Services: msdn.microsoft.com/library/cc668792.aspx. It implements the OData REST protocol (odata.org).Thraka– Thraka2013年01月22日 17:22:59 +00:00Commented Jan 22, 2013 at 17:22
3 Answers 3
I was asking myself the same question until I found this WCF and ASP.NET Web API comparison page on MSDN (with my own emphasis below):
Use WCF to create reliable, secure web services that accessible over a variety of transports. Use ASP.NET Web API to create HTTP-based services that are accessible from a wide variety of clients. Use ASP.NET Web API if you are creating and designing new REST-style services. Although WCF provides some support for writing REST-style services, the support for REST in ASP.NET Web API is more complete and all future REST feature improvements will be made in ASP.NET Web API. If you have an existing WCF service and you want to expose additional REST endpoints, use WCF and the WebHttpBinding.
IMO, having two APIs (two projects) is not a good approach: you are going to have maintenance problems, and you may confuse or trouble your service consumers / clients.
I would say it depends on your project requirements and client needs. If SOAP is a must, go with @Smokefoot's answer, use WCF and expose SOAP and REST endpoints. If no client wants to use SOAP any more and they want REST, stop the development on the WCF version (web service v1) and go for ASP.NET Web API (web service v2)
-
These days there are fewer real arguments for SOAP. Everything that the W3C Web Services architecture provided has a suitable replacement in a REST environment--including service discovery. ASP.NET Web API is going to be easier to write and maintain.Berin Loritsch– Berin Loritsch2017年09月06日 16:29:50 +00:00Commented Sep 6, 2017 at 16:29
This isn't really a direct answer to your question, but an alternative for you to explore.
In addition to my other answer, you can also check out another .NET web service framework called ServiceStack. Some good points about it:
- Open source.
- Support both SOAP and REST endpoints out of the box.
- Focus on performance, e.g. fastest text serializers in .NET, Redis support.
- Adhere to best practices, e.g. Martin Fowler's EAA, message-based web service.
- Extensive documentation at GitHub Wiki.
- Good support at StackOverflow with the
servicestack
tag, by the project creator Demis Bellot (aka. mythz).
Notable mentions comparing ServiceStack and ASP.NET Web API:
- ServiceStack vs ASP.Net Web API on StackOverflow.
- ServiceStack versus ASP .NET Web API on LinkedIn.
If you want to know more about ServiceStack, be sure to check out their official site, with codes and documentation at GitHub, and a presentation at slideshare.
The new Web API included in the new ASP.NET MVC is good for adding restful services to pages to enable some AJAX functionalities. It is good if you only want to have a small API or something like that but rest only.
In the moment where you implement REST and SOAP as a bigger API I would allways prefer to use a WCF application. I think this approach is better to maintain and you have all web services located in a central project.
-
Would you suggest implementing two different contracts? (one for rest and one for soap)Mithir– Mithir2012年08月28日 05:46:27 +00:00Commented Aug 28, 2012 at 5:46
-
I would suggest to implement two different contracts. The good thing about that is that same sharing the same functionality ;-) There are some applications doing this as well, like SharePoint (bad example ;-) )Smokefoot– Smokefoot2012年08月28日 07:09:45 +00:00Commented Aug 28, 2012 at 7:09
Explore related questions
See similar questions with these tags.