Search This Blog

Friday, September 16, 2011

Read & Write <system.serviceModel> section fom app.config file in C#

 

System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(typeof(ConfigOperation).Assembly.Location);

System.ServiceModel.Configuration.ServiceModelSectionGroup serviceModelSection = System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup(configuration);

//setting clientCertificateName
var enumer = serviceModelSection.Behaviors.EndpointBehaviors.GetEnumerator(); enumer.MoveNext();
System.ServiceModel.Configuration.EndpointBehaviorElement endpointBehaviour = (System.ServiceModel.Configuration.EndpointBehaviorElement)enumer.Current;
System.ServiceModel.Configuration.ClientCredentialsElement clientCred = (System.ServiceModel.Configuration.ClientCredentialsElement)endpointBehaviour.First();
clientCred.ClientCertificate.FindValue = "CERTIFICATE_NAME”;

//save config file
configuration.Save(System.Configuration.ConfigurationSaveMode.Modified, true);
   

No comments:

Post a Comment

If you like this post, please leave a comment :)