在配置文件中禁用ASP.net Rest服务 [英] Disable ASP.net Rest service in config file

查看:108
本文介绍了在配置文件中禁用ASP.net Rest服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个使用两个WCF REST服务的asp.net网站.这些其余服务之一仅在应用程序在QA环境中运行时才有效.因此,我正在寻找一种在发布到生产环境时禁用此功能的方法.

如何禁用配置文件中IIS中托管的REST wcf?

注意:如果我从网络配置中删除了服务配置部分,它将使用默认配置!因此该服务仍然有效!

有什么主意吗?

谢谢.

Hi Guys,

I have a asp.net web site which is using two WCF REST services. one of these rest services is just valid when the application is working in the QA env. so I am looking to find a way to disable this one when publishing to production.

How can I disable a REST wcf which is hosted in IIS in config file?

note: if I remove the service configuration part from web config it will use the default configuration! So the service still working!

any idea?

Thank you.

推荐答案

如评论中所述,最好的前进方法是为QA& A定义Web.Config文件.生产- Web.Config转换

以下MSDN Blog条目对此进行了解释:

更多详细信息:
MSDN:如何:在部署Web应用程序项目时转换Web.config [ ^ ]
MSDN:转换Web.Config文件以进行部署 [在ASP.NET中支持开发和发布web.config [ ^ ]
As mentioned in comments, best way to move ahead will be to have defined Web.Config files for QA & Production - Web.Config Transformation

Following MSDN Blog entry explains it: ASP.NET Web Projects: web.debug.config & web.release.config[^]

web.config

This is the config file which developers should use locally. Ideally you should get this to be standardized. For instance you could use localhost for DB strings, and what not. You should strive for this to work on dev machines without changes.

web.debug.config

This is the transform that is applied when you publish your application to the development staging environment. This would make changes to the web.config which are required for the target environment.

web.release.config

This is the transform that is applied when you publish your application to the "production" environment. Obviously you''ll have to be careful with passwords depending on your application/team.


More details:
MSDN: How to: Transform Web.config When Deploying a Web Application Project[^]
MSDN: Transforming a Web.Config File for Deployment[^]
Supporting Development and Release web.config in ASP.NET[^]


对于那些有相同问题的人,
我已经这样定义了我的svc文件:
For those who have the same problem,
I had defined my svc file like this:
<![CDATA[<%@ ServiceHost Language="C#" 

    Debug="true" 

    Service="ServiceName" 

    CodeBehind="~/App_Code/ServiceName.cs"

    Factory="System.ServiceModel.Activation.WebServiceHostFactory"

 %>]]>



通过这样做,即使我的web.config中没有任何配置,似乎IIS(或...)也激活了我的服务!因此,我从svc文件中删除了Factory ="..".通过这样做,我必须在配置文件中定义它,否则它将不起作用,因此我在配置文件中添加了以下额外的行:



by doing this, It seems IIS (or ...) activates my service even if I don''t have any configuration in my web.config! So the I removed the Factory=".." from the svc file. by doing this, I have to define it in the config file otherwise it will not work, so I added this extra lines to my config files:

<servicehostingenvironment aspnetcompatibilityenabled="true">
           <serviceactivations>
               <add relativeaddress="ServiceName.svc" service="ServiceName" factory="System.ServiceModel.Activation.WebServiceHostFactory" />
           </serviceactivations>
       </servicehostingenvironment>



现在一切都很好,每当我要禁用此服务时,都可以在配置文件中删除相关设置!

谢谢.



Now every thing is fine, when ever I want to disable this service, I can remove the related settings in the config file!

Thank you.


这篇关于在配置文件中禁用ASP.net Rest服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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