简体   繁体   中英

Not picking up dynamically swapped config info for WCF service called from VSTO Word AddIn

I have a C# VSTO Word AddIn from which I am successfully making WCF service calls. I am now trying to dynamically replace the config file (MyAddin.dll.config in my AddIn's base directory) from within the AddIn so I can redirect to other endpoints. Once I make the file change, I am using this code to refresh:

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationManager.RefreshSection("appSettings");
ConfigurationManager.RefreshSection("system.serviceModel/behaviors");
ConfigurationManager.RefreshSection("system.serviceModel/bindings");
ConfigurationManager.RefreshSection("system.serviceModel/client");
ConfigurationManager.RefreshSection("system.serviceModel/services");

I do not have any WCF clients open when I do this. After this refresh, when I immediately create a new client

var adminProxy = new CorrespondenceAdminClient();
mcRibbon.serviceHostUri = adminProxy.Endpoint.Address.Uri.ToString();

it appears to have picked up the new information, but when I call a service method, sometimes the call is directed to the correct endpoint and sometimes it is not . When I subsequently create a client and call a service from another part of my AddIn code, again it might or might not get to the expected endpoint. Sometimes the immediate call works but the subsequent call does not.

Is this information cached somewhere? Can I clear it?

I have tried running this from within and outside of the Visual Studio (Premium 2012) debugger and this does not make a difference.

它确实已缓存,您可以尝试在注册表https://msdn.microsoft.com/en-us/library/bb386106.aspx中添加“ | vstolocal”

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