Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET WCF .NET4
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 1-Oct-12 14:40pm
Comments
Ashraff Ali Wahab at 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 at 2-Oct-12 12:43pm
   
Thanks, but my question is how to configure it in web config as a disabled service?
Ashraff Ali Wahab at 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 at 2-Oct-12 15:11pm
   
Thanks for the answer, actually I found the solution! any way thank you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
v2
Comments
aidin Tajadod at 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 at 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 at 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!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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"
 %>]]>
 
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.
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100