none
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/");
        }
    }
    
    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?

     

    Thanks,

    Louis

    Monday, September 12, 2011 12:21 PM

Answers

All replies