开发者

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("CoreGetH开发者_运维问答andler", 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.


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


I found this solution : http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/350f2cb6-febd-4978-ae65-f79735d412db

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜