Self hosting asp.net RESTful webservice

♀尐吖头ヾ 提交于 2019-12-11 12:46:09

问题


I have a REST based web service which runs under IIS with name "WebHandler". I usually run the webservice under IIS and then write functional test code.

So everytime I run/debug a functional test, I have to keep the webservice running under IIS. Is there a way that in the functionaltest code, I can somehow host the webservice programatically so that the webservice is part of same process (NO IIS is involved) ? Benefits from this which I perceive is:

  1. modify webservice code on fly and test it.
  2. no more efforts for compiling the new webservice dll, putting it in IIS's bin folder and resetting IIS.

Something like Self hosting WCF service for e.g.

using (ServiceHost host = new ServiceHost(typeof(SaleClassLibrary.SaleService), baseAddress))
{
...
host.Open();
// do the end-to-end test
host.Close();
}

The above snippet I have taken from http://www.codeproject.com/Tips/622260/WCF-Self-Hosting-with-Example section 1 [self hosting]

Following is the snippet of my web.config if that is required

<system.webServer>
    <handlers>
        <add name="WebHandler" path="*" verb="*" type="Com.Tata.WebHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
    </handlers>
</system.webServer>

回答1:


Let me know if this helps you :

If you create a new WCF Service Application project, you'll have access to Web tab in the Properties window of the project, in which you can directly host your project on IIS and with every debug or run effort, you have the updated version of your service going.



来源:https://stackoverflow.com/questions/23558405/self-hosting-asp-net-restful-webservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!