Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I feel ya man. </p> <p>I don't like the idea that I have to embed the .config stuff into web.config when a WCF service is deployed into IIS, for example, or translate the .config and embed into code when hosting in some other way. </p> <p>The way I worked around it was to use a custom service host that overrides the default <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehostbase.applyconfiguration.aspx" rel="nofollow noreferrer">ApplyConfiguration()</a> logic. It allows, on the service side, the WCF DLL to look in dllname.dll.config (or anyplace, really) for its configuration.</p> <p>It is <a href="http://blogs.msdn.com/b/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx" rel="nofollow noreferrer">all explained here</a>. That information is also duplicated in <a href="https://stackoverflow.com/questions/211122/wcf-service-custom-configuration/619295#619295">this answer on Stackoverflow</a>.</p> <p>You're using a WCF client, so you need to override the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channelfactory.applyconfiguration.aspx" rel="nofollow noreferrer">ApplyConfiguration() method in a custom ChannelFactory</a>. This is described <a href="http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f33e620a-e332-4fd4-ae21-88c750437355/" rel="nofollow noreferrer">here</a>. On that same forum post, there is an alternative technique described where you override <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channelfactory.createdescription(v=VS.85).aspx" rel="nofollow noreferrer">CreateDescription()</a> and specify an alternative .config file path. These approaches are very similar; either should work in a WCF client.</p> <p>You might also consider embedding the .config as a resource embedded into the .dll. That way, you still have a single-file distribution (the dll), but you can use the xml config syntax to specify everything. At build time, embed the .config file into the DLL. At runtime inside your custom ApplyConfiguration(), you'd have to call <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcestream.aspx" rel="nofollow noreferrer">Assembly.GetManifestResourceStream();</a>, passing the string "dllname.dll.config" to get a read-only stream that contains the config information. </p> <p>If you want to allow the user to override the embedded config, then you could introduce that intelligence into your own ApplyConfiguration() implementation. Probably look for the filesystem file first; if it is not present, then fallback to the embedded .config file. </p> <p>This answer doesn't really tell you how to move config settings into code, because I think it is a heinous idea. But maybe it solves your problem anyway. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload