Friday, August 3, 2012

Programmatically reading endpoint address from web.config file?


There are some instances where we have to read wcf endpoint url from the code.As following you can accomplish that task.

once we add a service to the code it will get added to web.config under <system.serviceModel> section.

so we can access web config like this.

ServicesSection servicesSection = (ServicesSection)ConfigurationManager.GetSection(BASE_ADDRESS_PATH);

var item = servicesSection.Services[0].Host.BaseAddresses[0].BaseAddress;
Uri baseAddress = new Uri(item);

No comments:

Post a Comment