Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6944091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:14:28+00:00 2026-05-27T13:14:28+00:00

I am trying to create a tool to modify my service’s app.config file programmatically.

  • 0

I am trying to create a tool to modify my service’s app.config file programmatically. The code is something like this,

string _configurationPath = @"D:\MyService.exe.config";
ExeConfigurationFileMap executionFileMap = new ExeConfigurationFileMap();
executionFileMap.ExeConfigFilename = _configurationPath;

System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(executionFileMap, ConfigurationUserLevel.None);
ServiceModelSectionGroup serviceModeGroup = ServiceModelSectionGroup.GetSectionGroup(config);

foreach (ChannelEndpointElement endpoint in serviceModeGroup.Client.Endpoints)
{
    if (endpoint.Name == "WSHttpBinding_IMyService")
    {
        endpoint.Address = new Uri("http://localhost:8080/");
    }
}

config.SaveAs(@"D:\MyService.exe.config");

However I have problem changing the endpoint’s identity.

I want to have something like:

<identity>
     <userPrincipalName value="user@domain.com" />
</identity>

for my endpoint configuration, but when i try :

endpoint.Identity = new IdentityElement(){
    UserPrincipalName = UserPrincipalNameElement() { Value = "user@domain.com" }
}

It fails because the property endpoint.Identity and identityElement.UserPrincipalName is readonly (I’m not sure why, because entity.Address is not read-only)

Is there any way to get around this restriction and set the identity configuration?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:14:28+00:00Added an answer on May 27, 2026 at 1:14 pm

    I don’t think there is a way to do this built into the framework, at least I haven’t seen anything easy but could be wrong.

    I did see an answer to a different question, https://stackoverflow.com/a/2068075/81251, that uses standard XML manipulation to change the endpoint address. It is a hack, but it would probably do what you want.

    Below is the code from the linked answer, for the sake of completeness:

    using System;
    using System.Xml;
    using System.Configuration;
    using System.Reflection;
    
    namespace Glenlough.Generations.SupervisorII
    {
        public class ConfigSettings
        {
    
            private static string NodePath = "//system.serviceModel//client//endpoint";
            private ConfigSettings() { }
    
            public static string GetEndpointAddress()
            {
                return ConfigSettings.loadConfigDocument().SelectSingleNode(NodePath).Attributes["address"].Value;
            }
    
            public static void SaveEndpointAddress(string endpointAddress)
            {
                // load config document for current assembly
                XmlDocument doc = loadConfigDocument();
    
                // retrieve appSettings node
                XmlNode node = doc.SelectSingleNode(NodePath);
    
                if (node == null)
                    throw new InvalidOperationException("Error. Could not find endpoint node in config file.");
    
                try
                {
                    // select the 'add' element that contains the key
                    //XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", key));
                    node.Attributes["address"].Value = endpointAddress;
    
                    doc.Save(getConfigFilePath());
                }
                catch( Exception e )
                {
                    throw e;
                }
            }
    
            public static XmlDocument loadConfigDocument()
            {
                XmlDocument doc = null;
                try
                {
                    doc = new XmlDocument();
                    doc.Load(getConfigFilePath());
                    return doc;
                }
                catch (System.IO.FileNotFoundException e)
                {
                    throw new Exception("No configuration file found.", e);
                }
            }
    
            private static string getConfigFilePath()
            {
                return Assembly.GetExecutingAssembly().Location + ".config";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to create a screen similar to this: Using this tool to
I am trying to create a code coverage tool using Delphi 2007. My general
I'm trying to create a search tool and would like to display the results
I'm trying to create a tool that can generate XSDs for the XAML produced
I'm trying to create a generic graphics export tool which works by implementing the
First, context: I'm trying to create a command-line-based tool (Linux) that requires login. Accounts
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
I'm trying to create a Java Tool by using Xcode. I've already changed my
I am trying to create a table over inputs to a tool which requires

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.