So, due to some concerns, I’ve split up what was initially a single interface contract into two separate ones. Now, I have only one class (partial) implementing both interfaces, and I want to make them all available as REST-services through WCF. The contracts are listed below.
I am using Autofac for WCF service host.
Below is my .svc file code
For WCF service: Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"
For RESTful service: Factory="Autofac.Integration.Wcf.AutofacWebServiceHostFactory, Autofac.Integration.Wcf"
WCF Example:
For wcf service
public interface IEmployeeCommandService {}
public interface IEmployeeQueryService {}
public partial class EmployeeService : IEmployeeCommandService {}
public partial class EmployeeService : IEmployeeQueryService {}
public partial class EmployeeService {}
And my Web.config file looks like below
<service behaviorConfiguration="ServiceBehavior" name="Application.EmployeeService">
<endpoint address="" binding="basicHttpBinding" contract="Application.IEmployeeCommandService" />
<endpoint address="" binding="basicHttpBinding" contract="Application.IEmployeeQueryService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
And my EmployeeService.svc code looks like
<%@ ServiceHost Service="Application.EmployeeService, Application"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"%>
with this approach the plain WCF service working fine for me. When browse the EmployeeService.svc I can see both command & Query service operations.
Simillar approach I am trying for RESTFul service as mentioned like below. But I am getting error when I browse my RESTFul service.
RESTFul Example:
public interface IEmployeeRESTfulQueryService {}
public interface IEmployeeRESTfulCommandService {}
public partial class EmployeeRESTfulService {}
public partial class EmployeeRESTfulService : IEmployeeRESTfulCommandService {}
public partial class EmployeeRESTfulService : IEmployeeRESTfulQueryService {}
And My web.confing looks like below
<service behaviorConfiguration="ServiceBehavior" name="Application.EmployeeRESTfulService">
<endpoint name="Command" address="Command" behaviorConfiguration="webHttp" binding="webHttpBinding" contract="Application.IEmployeeRESTfulCommandService" />
<endpoint name="Query" address="Query" behaviorConfiguration="webHttp" binding="webHttpBinding" contract="Application.IEmployeeRESTfulQueryService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<behavior name="webHttp">
<webHttp helpEnabled="true" automaticFormatSelectionEnabled ="true" />
</behavior>
If I browse my .svc (RESTFul) I endup with below error..
Error:
Service ‘EmployeeRESTfulService’ 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..
Factory=System.ServiceModel.Activation.WebServiceHostFactoryon the .svc file? If so, remove the Factory attribute, since you’re defining the endpoints in config.Update following edit: the
Factoryused by the restful service,Autofac.Integration.Wcf.AutofacWebServiceHostFactory, Autofac.Integration.Wcf, is using theWebServiceHost, which requires the service class to implement only one[ServiceContract]interface. Do you need the Autofac factory? If not, just remove that attribute; otherwise, since you’re already defining the endpoints via config, I imagine it should work with the “normal” factory (AutofacServiceHostFactory) as well (I’ve never used Autofac, but you can try that).