IT:AD:WCF:HowTo:Not Use CodeBehind
Summary
How can I host in IIS a *.svc page that doesn't use CodeBehind, but instead uses a class defined ina referencedassembly?
Process
- Create a Dll to host the Svc Interfaces and Implementation:
Example:
// NOTE: "Refactor"/"Rename" command to rename interface in both code and config. [ServiceContract(Name = "WorkflowService")] public interface IWorkflowService { /// <summary> /// Method to call from a Filewatcher to start a workflow type. /// </summary> [OperationContract(Name = "Start")] void Start(int workflowTypeId); }
* In the website:
- Add a *.svc file
- Right-click,
View Markup
- Rewire to point to external dll.
Example:
//Before: <%@ ServiceHost Language="C#" Debug="true" Service="Nab.Wdms.PM.UI.Web.WCF.Service1" CodeBehind="Service1.svc.cs" %> //After: <%@ ServiceHost Language="C#" Service="Nab.Wdms.PM.Appfacade.WorkflowService" Debug="true" %>
Note: In the Svc file: * The Service="..." attribute is a Type FQN that points to the Instance, not the > * The Service="..." attribute . * If in the same assembly, it can be just a FullName, but when in a different assembly, a FQN must be provided ("ExtNS.ExtService, ExtAssembly") * Remove the CodeBehind="..." attribute
> In the config file:
* The Service element's name is also the name of the Service type, but it's not the FQN. * Therefore you just give name="ExtNS.ExtService" & Same for the Contract="..." attribute on endpoint attributes. Even though they are in alternate assemblies, it doesn't want a FQN -- just the Type Name (with namespace).Give either one a FQN, and it won't find it..