简体   繁体   中英

Determine host type ( selfhost vs iis ) for a wcf service exposing basichttp binding

There is a service , exposing one endpoint as basic http binding. I have two types of hosting ( selfhost for test ,iis for production)

I am using configurationmanager which has to read a service model section from config. Of course , when it is self host a config file is myapp.exe.config located in the same path as executing assembly and when it is running under iss , it is web.config .

So i want to use configurationmanager.openmappedexeconfiguration and provide it a path to config.

But i need to understand what hosting type is used now. There is no httpcontex.current because it is basic http binding. ( if it was , i would be able to use it in order to check if its is null and if not, it is iss hosting ).

How to solve the problem ?

I am a little bit confused: ConfigurationManager should know to read appSettings from bith appp and web config.

You also probably need not to read Service Model section by your self - let wcf do it for you. It also can care about config.

You can also setup service details in code - to avoid config search.

If you have no choice (i'd use as last option) - may be try to use Assembly's running exe path, like Assembly.GetExecutingAssembly()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM