I'm trying to convert a WCF/REST service project to MVC/WebAPI. The service layer is implemented multiple times as a wrapper for different end systems, and all implementations observe a common contract defined in an interface (IContract
). With WCF, we defined [WebInvoke]
and [OperationContract]
attributes on each of the methods which were exposed as web service methods. In WebAPI, this can be simplified with attribute routing defined on the controller. However, I would like to keep the route attributes defined on the interface, so all the implementations behave similarly.
Here's a sample of the old interface:
[ServiceContract]
public interface IContract
{
[WebInvoke(UriTemplate = "Version", Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
[OperationContract]
string GetVersion();
}
Here's what I was hoping to get working:
public interface IContract
{
[Route("Version")]
[HttpGet]
string GetVersion();
}
I would also consider creating an abstract base class, but this other StackOverflow question makes me think there isn't a suitable replacement for [WebInvoke(UriTemplate)]
using WebAPI attribute routing. Is that the case, or can someone point me to a similar, supported technique?
Thanks