【发布时间】:2014-05-09 06:58:55
【问题描述】:
我有一个基于 REST 的 Web 服务,它在 IIS 下运行,名称为“WebHandler”。我一般是在IIS下运行webservice,然后编写功能测试代码。
所以每次我运行/调试功能测试时,我都必须让 web 服务在 IIS 下运行。有没有办法在功能测试代码中,我可以以某种方式以编程方式托管 web 服务,以便 web 服务是同一进程的一部分(不涉及 IIS)?我认为这样做的好处是:
- 即时修改 Web 服务代码并进行测试。
- 无需再编译新的 webservice dll,将其放入 IIS 的 bin 文件夹并重置 IIS。
类似于自托管 WCF 服务,例如
using (ServiceHost host = new ServiceHost(typeof(SaleClassLibrary.SaleService), baseAddress))
{
...
host.Open();
// do the end-to-end test
host.Close();
}
上面的 sn-p 我取自http://www.codeproject.com/Tips/622260/WCF-Self-Hosting-with-Example section 1 [self hosting]
如果需要,以下是我的 web.config 的 sn-p
<system.webServer>
<handlers>
<add name="WebHandler" path="*" verb="*" type="Com.Tata.WebHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
</handlers>
</system.webServer>
【问题讨论】:
-
我不确定旧的 asmx webservices,但你可以自己托管 Restful web API。 asp.net/web-api/overview/hosting-aspnet-web-api/…
标签: asp.net web-services wcf iis functional-testing