WCF Configuration - Split it out of app.config

前端 未结 8 1611
耶瑟儿~
耶瑟儿~ 2020-12-10 02:38

I have a specific requirement to remove all client WCF configuration () out of the main app.config file, and into a separate XML file. The behav

8条回答
  •  抹茶落季
    2020-12-10 03:12

    I have a tendency to programatically configure all my service settings.

    My clients aren't really the type to understand XML and have asked me make configuration files more like the old INI style.

    This is easy to do (reading INI file code not included):

            // create the URI which is used as the service endpoint
            Uri tcpBaseAddress = new Uri(
                    string.Format("net.tcp://{0}:{1}",
                        LocalIPAddress.ToString(), GeneralPortNumber));
    
            // create the net.tcp binding for the service endpoint
            NetTcpBinding ntcBinding = new NetTcpBinding();
            ntcBinding.Security.Mode = SecurityMode.None;
            System.ServiceModel.Channels.Binding tcpBinding = ntcBinding;
    
            // create the service host and add the endpoint
            Host = new ServiceHost(typeof(WordWarService), tcpBaseAddress);
    

    Since we can configure the host (and client, for that matter) programatically there is nothing keeping you from supplying the settings in any manner you choose (database, xml, crazy text file, etc).

提交回复
热议问题