Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Comments
Ashraff Ali Wahab 1-Oct-12 23:39pm    
You can have two config one is Web.Release.config and Web.Debug.config and use it appropriately.
aidin Tajadod 2-Oct-12 12:43pm    
Thanks, but my question is how to configure it in web config as a disabled service?
Ashraff Ali Wahab 2-Oct-12 14:21pm    
I though you configured the URL's in the config.In one config have both teh URLS and in one have only one URL.If I am workng could you post your config file.
aidin Tajadod 2-Oct-12 15:11pm    
Thanks for the answer, actually I found the solution! any way thank you.

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[^]
 
Share this answer
 
v2
Comments
aidin Tajadod 2-Oct-12 12:41pm    
Thanks for the answer,but my question is how to make it disable in config file? I could not find a way to do so!
Sandeep Mewara 2-Oct-12 13:19pm    
If you would have gone through links you would have got that switching web.config file one with enabled and other with disabled key would do the trick.
aidin Tajadod 2-Oct-12 14:10pm    
OK, I think you did not get my question! I don't have problem switching them, I do not know how to change the web config so to disable it!
For those who have the same problem,
I had defined my svc file like this:
HTML
<![CDATA[<%@ ServiceHost Language="C#" 
    Debug="true" 
    Service="ServiceName" 
    CodeBehind="~/App_Code/ServiceName.cs"
    Factory="System.ServiceModel.Activation.WebServiceHostFactory"
 %>]]>


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:

HTML
<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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900