Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a WCF .NET service implementation implement multiple ServiceContract interfaces
    text
    copied!<p>I am developing a RESTful webservice using WCF. I would like to have a <code>ServiceContract</code> interface that all my services implement, however, I would also like each service to aditionally implement their own methods.</p> <p>In my Global.asax file I initialize the service routes:</p> <pre><code>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))); </code></pre> <p>Each of the services must implement the <code>IAppService</code> interface:</p> <pre><code>[ServiceContract] public interface IAppService </code></pre> <p>Which is implemented as follows:</p> <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class iOSAppService : IAppService </code></pre> <p>However, I would for instance also like the <code>iOSAppService</code> to implement the IiOSApService interface:</p> <pre><code>[ServiceContract] public interface IiOSAppService </code></pre> <p>Thus resulting in the implementation:</p> <pre><code>public class iOSAppService : IAppService, IiOSAppService </code></pre> <p>However, this results in the following exception:</p> <blockquote> <p><em>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.</em></p> </blockquote> <p>Does anyone know how I can achieve my goal?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload