Reputation: 9171
I have a class library that has a reference to a web service and I include this class library in my web.config.
Now I want to be able to dynamically change the url of the web service (like you would normally do in the web.config). How can I do this? I tried putting the settings into the web.config, but changing it has no effect.
<applicationSettings>
<MyClassLibraryAppConfig.WCFServices.Properties.Settings>
<setting name="WebServiceKey"
serializeAs="String">
<value>http://localhost/badaddress.asmx</value>
</setting>
</MyClassLibraryAppConfig.WCFServices.Properties.Settings>
</applicationSettings>
<applicationSettings>
<MyApp.Properties.Settings>
<setting name="WebServiceKey"
serializeAs="String">
<value>http://localhost/goodaddress.asmx</value>
</setting>
</MyApp.Properties.Settings>
</applicationSettings>
Upvotes: 2
Views: 1190
Reputation: 2059
Moving the web service url to the host application's web.config is definitely the way to go in most cases. You mentioned that changing the value in the web.config file has no effect but I'd double-check that. Unless you have the url hard-coded, that's the location where the host process would read it from.
Upvotes: 2
Reputation: 161783
If you are using a web reference, then see Ways to Customize your ASMX Client Proxy. If you are using WCF, then you can use the overload of the proxy class constructor which includes an EndpointAddress.
Upvotes: 0