Host a Wcf Service Library in a Web Application

By : Jni

I would like to host a Wcf Service, create in a Wcf service Library, in a Web Application.

I've already done the same thing with Web Service asmx :

using System.Reflection;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace WebServiceLibrary
    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class WebService1 : WebService, IHttpHandlerFactory
        private static WebServiceHandlerFactory wshf = new WebServiceHandlerFactory();
        private static MethodInfo coreGetHandlerMethod = typeof(WebServiceHandlerFactory).GetMethod("CoreGetHandler", BindingFlags.Instance | BindingFlags.NonPublic);

        public System.Web.IHttpHandler GetHandler(System.Web.HttpContext context, string requestType, string url, string pathTranslated)
            return (IHttpHandler)coreGetHandlerMethod.Invoke(wshf, new object[] { GetType(), context, context.Request, context.Response });

        public void ReleaseHandler(IHttpHandler handler)


        public string HelloWorld()
            return "Hello World";

The web.config file of the Web Application :

          <add name="WebService" path="WebService1.asmx" verb="*" preCondition="integratedMode" type="WebServiceLibrary.WebService1"/>

Is here a way to do the same thing with a Wcf Service ?


By : Jni


Sure - the simplest thing would likely be to create a new 'WCF Service Application' (which is a webapp) and use that as a template in terms of what bits you would need, for instance the system.serviceModel section in your web.config

This video can help you solving your question :)
By: admin