WCF 4.0 REST JSON - get web.config <system.serviceModel> value RRS feed

  • Question

  • hi, experts, 

    I have my own serviceAuthorization for my wcf 4.0 rest json platform.

     protected override bool CheckAccessCore(OperationContext operationContext)
                _errorCode = string.Empty;
                _errorMessage = string.Empty;
                bool result = Authenticate(operationContext);            
                if (operationContext.RequestContext.RequestMessage.Headers.To.OriginalString.ToUpper().EndsWith(@"/HELP"))
                    result = true;
                return result;

    in my web.config, I have set helpEnabled="true"

            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" defaultOutgoingResponseFormat="Json" />        

    as I have customized the CheckAccessCore function.

    help page may not work if the validation in CheckAccessCore fucntion return false.

    I would like to always return true if the request url is to helppage.

    how to get the helpEnabled value in web.config from C# code behind? 

    thank you very much!

    Thursday, February 20, 2014 2:18 AM

All replies

  • You would do the following:

    1. First get the configuration.
    2. Get the section group for system.serviceModel.
    3. Check the properties of the section group to find the value you're looking for.

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
    ServiceModelSectionGroup section = config.GetSectionGroup("system.serviceModel"as ServiceModelSectionGroup;  
    string address = section.Client.Endpoints[0].Address.OriginalString; 

    The code above has the following using statements:

    using System.Configuration;
    using System.ServiceModel.Configuration;
    Friday, February 21, 2014 10:21 AM