I am developing a RESTful webservice using WCF. I would like to have a ServiceContract interface that all my services implement, however, I would also like each service to aditionally implement their own methods.
In my Global.asax file I initialize the service routes:
RouteTable.Routes.Add(new ServiceRoute("iOSAppService", new WebServiceHostFactory(), typeof(Service.iOSAppService)));
RouteTable.Routes.Add(new ServiceRoute("AndroidAppService", new WebServiceHostFactory(), typeof(Service.AndroidAppService)));
RouteTable.Routes.Add(new ServiceRoute("WindowsPhoneAppService", new WebServiceHostFactory(), typeof(Service.WindowsPhoneAppService)));
Each of the services must implement the IAppService interface:
[ServiceContract]
public interface IAppService
Which is implemented as follows:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class iOSAppService : IAppService
However, I would for instance also like the iOSAppService to implement the IiOSApService interface:
[ServiceContract]
public interface IiOSAppService
Thus resulting in the implementation:
public class iOSAppService : IAppService, IiOSAppService
However, this results in the following exception:
Service ‘iOSAppService’ implements multiple ServiceContract types, and no endpoints are defined in the configuration file. WebServiceHost can set up default endpoints, but only if the service implements only a single ServiceContract. Either change the service to only implement a single ServiceContract, or else define endpoints for the service explicitly in the configuration file.
Does anyone know how I can achieve my goal?
Make your specyfic interface like this:
And then
Edit:
On service side make sure you have: