自托管asp.net RESTful Web服务 [英] Self hosting asp.net RESTful webservice

查看:259
本文介绍了自托管asp.net RESTful Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于REST的Web服务,该服务在IIS下以名称"WebHandler"运行.我通常在IIS下运行Web服务,然后编写功能测试代码.

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.

因此,每次我运行/调试功能测试时,都必须使Web服务在IIS下运行.有没有一种方法可以在功能测试代码中以某种方式以编程方式托管Web服务,以使Web服务成为同一进程的一部分(不涉及IIS)?我感觉到的好处是:

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. 动态修改Web服务代码并对其进行测试.
  2. 没有更多的工作来编译新的webservice dll,将其放入IIS的bin文件夹中并重置IIS.

例如自托管WCF服务之类的东西

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();
}

我摘录自 http://www .codeproject.com/Tips/622260/WCF-Self-Hosting-with-Example 第1节[自我托管]

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

以下是我的web.config的摘录

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>

推荐答案

让我知道这是否对您有帮助:

Let me know if this helps you :

如果您创建一个新的WCF服务应用程序项目,则可以访问该项目的 Properties 窗口中的 Web 标签,您可以在其中直接托管您的在IIS上进行项目,并且每次调试或运行时,您都会获得服务的更新版本.

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.

这篇关于自托管asp.net RESTful Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆