如何使用dll在IIS上托管Web服务

时间:2012-06-29 14:58:34

标签: wcf web-services iis iis-7 web-hosting

我需要在IIS上托管一个Web服务。我之前做过这个,我将有一个.svc(WCF)文件或asmx文件。但从来没有只用一个DLL。我该如何设置?

1 个答案:

答案 0 :(得分:1)

使用asp.net兼容模式创建一个类似的类......

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode =  AspNetCompatibilityRequirementsMode.Required)]
public class MyService    
{

//Some methods

}

将global.asax文件中的类注册为Web服务

public class Global : System.Web.HttpApplication
{

    public void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes();
    }

    private static void RegisterRoutes()
    {
        RouteTable.Routes.Add(new ServiceRoute("myServiceUrl", new WebServiceHostFactory(), typeof(MyService)));
    }
}

如果您的应用程序在端口8080上运行,则可以在

处点击该服务
http://localhost:8080/myServiceUrl