asp.net - Configuring WCF Services in Code WCF 4.5 -


hi, trying configure wcf using code behind, below code:

public static void configure(serviceconfiguration config)    {        string configpath = configurationmanager.appsettings["wcfconfigdbpath"];      // enable “add service reference” support      config.description.behaviors.add(new servicemetadatabehavior { httpgetenabled = true });     // set support http, https, net.tcp, net.pipe      if (isenabled(configpath, "enablehttp"))         config.enableprotocol(new basichttpbinding());     if (isenabled(configpath, "enablenettcp"))         config.enableprotocol(new nettcpbinding());     if (isenabled(configpath, "enablepipe"))         config.enableprotocol(new netnamedpipebinding());  } private static bool isenabled(string path, string elementname) {     try     {         string elementvalue = string.empty;         bool returnval = false;         using (xmltextreader reader = new xmltextreader(path))         {              reader.readtofollowing(elementname);             if (reader.read())                 elementvalue = reader.value;          }         if (!string.isnullorempty(elementvalue))         {             bool.tryparse(elementvalue, out returnval);         }         return returnval;      }     catch (exception ex)     {         return false;     } } 

the above code not working. not sure when "static void configure" gets fired.

my question is, there way enable/disable protocol based on db/xml configuration without bringing down service?

new feature in .net 4.5 can used in case:

note: configure method called wcf before service host opened.

the configure method takes serviceconfiguration instance enables developer add endpoints , behaviors. method called wcf before service host opened. when defined, service configuration settings specified in app.config or web.config file ignored. following code snippet illustrates how define configure method , add service endpoint, endpoint behavior , service behaviors:

public class service1 : iservice1 {     public static void configure(serviceconfiguration config)     {         serviceendpoint se = new serviceendpoint(new contractdescription("iservice1"), new basichttpbinding(), new endpointaddress("basic"));         se.behaviors.add(new myendpointbehavior());         config.addserviceendpoint(se);          config.description.behaviors.add(new servicemetadatabehavior { httpgetenabled = true });         config.description.behaviors.add(new servicedebugbehavior { includeexceptiondetailinfaults = true });     }      public string getdata(int value)     {         return string.format("you entered: {0}", value);     }      public compositetype getdatausingdatacontract(compositetype composite)     {         if (composite == null)         {             throw new argumentnullexception("composite");         }         if (composite.boolvalue)         {             composite.stringvalue += "suffix";         }         return composite;     } } 

refer complete example to:https://msdn.microsoft.com/en-us/library/hh205277(v=vs.110).aspx


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -