How to programmatically change an endpoint's identity configuration? RRS feed

  • Question

  • Hi,

    I am trying to create a tool to modify my service's 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/");

    However I have problem changing the endpoint's identity.

    I want to have something like:

              <userPrincipalName value="" />


    for my endpoint configuration, but when i try :

    endpoint.Identity = new IdentityElement(){
            UserPrincipalName = UserPrincipalNameElement() { Value = "" }

    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?




    Monday, September 12, 2011 12:21 PM


All replies