简体   繁体   中英

Host a Wcf Service Library in a Web Application

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 = "http://tempuri.org/")]
    [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)
        {

        }

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

The web.config file of the Web Application :

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

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

Regards.

当然-最简单的事情可能是创建一个新的“ WCF服务应用程序”(它是一个Web应用程序),并根据需要的位数将其用作模板,例如,web.config中的system.serviceModel部分

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM