wcf - Get setting from C# App.config file -
i have app.config file. it's sample given me api have use... want setting file can use settings there , not have duplicate efforts.
how can words "findme", "localmachine" , "my" in app.config file (to drive pulling certificate given information)?
<?xml version="1.0" encoding="utf-8"?> <configuration> <startup>...</startup> <system.servicemodel> <bindings>...</bindings> <client>...</client> <behaviors> <endpointbehaviors> <behavior name="clientcertificatebehavior"> <clientcredentials> <clientcertificate findvalue="findme" storelocation="localmachine" storename="my" x509findtype="findbysubjectname"/> <servicecertificate><authentication certificatevalidationmode="none"/></servicecertificate> </clientcredentials> </behavior> </endpointbehaviors> </behaviors> </system.servicemodel> </configuration> i'm looking see if can find in system.servicemodel.configuration or configurationmanager, i'm not seeing how specific values.
edit:
i think i'm real close, can't seem values.

once have access servicemodelsectiongroup, can access various parts of model. eg behaviors.endpointbehaviors collection
public servicemodelsectiongroup getservicemodelsectiongroup() { var cfg = getconfig(); servicemodelsectiongroup servicemodelsection = servicemodelsectiongroup.getsectiongroup(cfg); return servicemodelsection; } public configuration getconfig() { if (_cfg == null) { if (hostingenvironment.ishosted) // running inside asp.net ? { //yes read web.config @ hosting virtual path level _cfg = webconfigurationmanager.openwebconfiguration(hostingenvironment.applicationvirtualpath); } else { //no, se testing or running exe version admin tool example, app.config file //var x = appdomain.currentdomain.setupinformation.configurationfile; _cfg = configurationmanager.openexeconfiguration(configurationuserlevel.none); } } return _cfg; }
Comments
Post a Comment