Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NETWCF.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:40

Comments
Ashraff Ali Wahab - 1 Oct '12 - 23:39
You can have two config one is Web.Release.config and Web.Debug.config and use it appropriately.
aidin Tajadod - 2 Oct '12 - 12:43
Thanks, but my question is how to configure it in web config as a disabled service?
Ashraff Ali Wahab - 2 Oct '12 - 14:21
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:11
Thanks for the answer, actually I found the solution! any way thank you.

2 solutions

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  
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  
Comments
aidin Tajadod - 2 Oct '12 - 12:41
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:19
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:10
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!

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Mahesh Bailwal 353
1 Sergey Alexandrovich Kryukov 339
2 Maciej Los 290
3 CPallini 245
4 Rohan Leuva 175
0 Sergey Alexandrovich Kryukov 9,162
1 OriginalGriff 7,194
2 CPallini 3,923
3 Rohan Leuva 3,176
4 Maciej Los 2,633


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid