private void GenerateServiceConfiguration()
{
// Get a pointer to system.serviceModel section.
ConfigurationSectionGroup csg = configuration.SectionGroups["system.serviceModel"];
// Notify if we get a null reference.
Debug.Assert(csg != null, "system.serviceModel section could not be found in the configuration.");
if (csg != null)
{
// Get a reference to the client section.
ClientSection cs = csg.Sections["client"] as ClientSection;
// Also get a reference to the services section.
ServicesSection ss = csg.Sections["services"] as ServicesSection;
// If there is no services section, we create a new one.
if (ss == null)
{
// Create a new services section.
ss = new ServicesSection();
// Add it to the sections collection.
csg.Sections.Add("services", ss);
}
string fqServiceTypeName = GetFullyQulifiedTypeName(GetServiceTypeName());
ServiceElement se = new ServiceElement(fqServiceTypeName);
ss.Services.Add(se);
if (cs != null)
{
foreach (ChannelEndpointElement cee in cs.Endpoints)
{
// TODO: May be we will want to give an option to use fully qulified interface names
// in the endpoints.
ServiceEndpointElement see = new ServiceEndpointElement(cee.Address, cee.Contract);
see.BehaviorConfiguration = cee.BehaviorConfiguration;
see.BindingConfiguration = cee.BindingConfiguration;
see.Binding = cee.Binding;
se.Endpoints.Add(see);
}
csg.Sections.Remove("client");
}
}
}