The Refernce.cs file created by Visual Studio indicates that the web service URL will be obtained from the settings:
this.Url = global::ConsoleApplication1.Properties. Settings.Default.ConsoleApplication1_net_webservicex_www_BarCode;
I believe that John Saunders gave you a wonderful suggestion in his comment. You need a SettingsProvider class that:
... defines the mechanism for storing configuration data used in application architecture .. The .NET Framework contains a single default settings provider, LocalFileSettingsProvider, which stores configuration data on the local file system. However, you can create alternative storage engines by getting the abstract sets the Provider class. A provider that uses a wrapper class is defined by decorating the wrapper class with SettingsProviderAttribute. If this attribute is not specified, the default is LocalFileSettingsProvider.
I don’t know how much you have progressed after this approach, but it should go pretty well:
Create the SettingsProvider class:
namespace MySettings.Providers { Dictionary<string, object> _mySettings; class MySettingsProvider : SettingsProvider {
Extend the class definition for the partial project class YourProjectName.Properties.Settings and decorate it with SettingsProviderAttribute :
[System.Configuration.SettingsProvider(typeof(MySettings.Providers.MySettingsProvider))] internal sealed partial class Settings {
In the overridden GetPropertyValues method, you should get the display value from the _mySettings dictionary:
public override SettingsPropertyValueCollection GetPropertyValues( SettingsContext context, SettingsPropertyCollection collection) { var spvc = new SettingsPropertyValueCollection(); foreach (SettingsProperty item in collection) { var sp = new SettingsProperty(item); var spv = new SettingsPropertyValue(item); spv.SerializedValue = _mySettings[item.Name]; spv.PropertyValue = _mySettings[item.Name]; spvc.Add(spv); } return spvc; }
As you can see in the code, for this you need to know the name of the parameter that was added to app.config and Settings.settings when you added the link to the web service ( ConsoleApplication1_net_webservicex_www_BarCode ):
<applicationSettings> <ConsoleApplication30.Properties.Settings> <setting name="ConsoleApplication1_net_webservicex_www_BarCode" serializeAs="String"> <value>http://www.webservicex.net/genericbarcode.asmx</value> </setting> </ConsoleApplication30.Properties.Settings> </applicationSettings>
This is a very simple example, but you can use a more complex object to store configuration information in combination with other properties available in the context, such as item.Attributes or context , to get the correct configuration value.
Alex filipovici
source share