none
WCF Service Configure method does not execute RRS feed

  • Question

  • My application uses WCF services, and I'm trying to reduce the amount of editing that needs to be done on the service's web.config file when my services change. The service application is built to target .NET 4.5.2, so I thought I could use the Configure method to load my service's configuration from a separate file, but the Configure method was never called.

    My implementation class implements my service interface, and the Interface does have the [ServiceContract] attribute. Any suggestions would be appreciated.

    Wednesday, January 24, 2018 5:50 PM

All replies

  • My implementation class implements my service interface, and the Interface does have the [ServiceContract] attribute. Any suggestions would be appreciated.

    My suggestion is don't do it and use the config file traditionally, or program code the configuration in the code and not use a config file at all.

    Wednesday, January 24, 2018 8:59 PM
  • Hi Eduardo,

    Could you share us how you used Configure method?

    I made a test with code below, put a breakpoint at the line of "Configure", it is hit when I access http://localhost/WCFRestSvc/Service1.svc while debugging.

    IService.cs

        [ServiceContract]
        public interface IService1
        {        
            [OperationContract]
            string GetData(int value);      
        }

    Service.cs

        public class Service1 : IService1
        {
            public static void Configure(ServiceConfiguration config)
            {
                config.LoadFromConfiguration(ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap {
                    ExeConfigFilename = @"file path"
                }, ConfigurationUserLevel.None));
            }
            public string GetData(int value)
            {
               return "Hello World";
            }     
        }

    #onfiguring WCF Services in Code

    https://docs.microsoft.com/en-us/dotnet/framework/wcf/configuring-wcf-services-in-code

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, January 25, 2018 2:08 AM