Reputation: 193
I have created REST service with WCF and i have different contracts(Contract1, Contract2, etc..).
This is configuration in web.config
<endpoint address="users" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IUserService"/>
<endpoint address="actors" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IActorService"/>
<endpoint address="films" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IFilmService"/>
It's the example of contract.
[OperationContract]
[WebGet(UriTemplate = "?offset={offset}&count={count}", ResponseFormat = WebMessageFormat.Json)]
Films GetFilms(string offset, string count);
So my question is how i can use same address for all endpoints (localhost/rest). Because i need contract UriTemplate more flexible, for example if i need return list of films by category (uri example: localhost/rest/category/2). But with this uri and current configuration (address property in web.config) I must put this method into Category contract. But in mine opinion this methid must be in Films contract. So does it has solution or it's normal?
Upvotes: 1
Views: 555
Reputation: 661
If you want to expose multiple contracts with a single endpoint, then you have to have one of the contracts inherit from the other one. Then have your endpoint expose the derived contract. Like the following:
[ServiceContract]
IFilmService : IActorService
Then have one endpoint:
<endpoint address="rest" binding="webHttpBinding" behaviorConfiguration="web" contract="FilmInfoApi.Service.IFilmService"/>
Upvotes: 1