![](/img/trans.png)
[英]WCF Service on IIS. How to get rid of the “Service.svc” component in the URL path?
[英]When Will the Default Constructor of Service.svc in a WCF Service is executed?
這是示例代碼
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class Service : IService
{
public Service()
{
// here I am getting value from web.config
// using configurationManager which will be
// changing frequently
}
//Method1
....
//Method2
.....
}
我的服務的構造函數什么時候執行? 在第一個請求中還是在每個請求中?
對於服務的每個請求/調用,都會調用構造函數。
另外, 更改 web.config時,如果您的應用程序托管在IIS中,則應用程序池將回收。
如果您通過下面的瀏覽器使用/調用WCF服務,則每次調用都會創建服務的新對象,因此請執行服務的默認構造函數。
瀏覽器調用:... / priceatadataservice / DataService.svc / web / GetHistoryData
但是,如果您通過添加對其他項目的引用來調用服務,則僅當您創建服務對象時,它才是調用/執行構造函數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.