Hi, Everybody!...
I created a web service (i.e., MyService). The web service references other dependent web services (i.e., DependentService). I have three environments: LOCAL, TEST and LIVE. I develop my code in the LOCAL environment (i.e., my computer). Then I deploy to the TEST environment (i.e., a TEST server) for testing. Finally, when testing completes successfully, I deploy to the LIVE environment (i.e., a LIVE server).
MyService has an Environment appSettings in the Web.config file. I use this appSettings to tell MyService which drive is the DataDrive and which database to talk to in each environment.
<appSettings>
<!--ENVIRONMENT (LOCAL/TEST/LIVE)-->
<add key="Environment" value="LOCAL"/>
<!--DATA DRIVE-->
<add key="DataDriveLOCAL" value="C:"/>
<add key="DataDriveTEST" value="D:"/>
<add key="DataDriveLIVE" value="D:"/>
</appSettings>
<connectionStrings>
<!-- LOCAL/TEST/CLOUD -->
<add name="OpsConnectionStringLOCAL" connectionString="<LOCAL Connection String>" providerName="System.Data.SqlClient"/>
<add name="OpsConnectionStringTEST" connectionString="<TEST Connection String>" providerName="System.Data.SqlClient"/>
<add name="OpsConnectionStringLIVE" connectionString="<LIVE Connection String>"System.Data.SqlClient" />
</connectionStrings>
I wish to do the same with the dependent web services. However, when I add a dependent web service, a lot of code (Reference.cs) and settings (Settings.Designer.cs) are generated automagically "under the hood".
Reference.cs
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
//
// This source code was auto-generated by Microsoft.VSDesigner, Version 4.0.30319.42000.
//
#pragma warning disable 1591
namespace MyService.DependentService
{
using System.Diagnostics;
using System;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Web.Services.Protocols;
using System.Web.Services;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.8.4084.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name = "ServiceSoap", Namespace = "http://MyDomain.com/")]
public partial class Service : System.Web.Services.Protocols.SoapHttpClientProtocol
{
// <SNIP/>
public Service()
{
this.Url = global::MyService.Properties.Settings.Default.MyService_DependentService;
if ((this.IsLocalFileSystemWebService(this.Url) == true))
{
this.UseDefaultCredentials = true;
this.useDefaultCredentialsSetExplicitly = false;
}
else
{
this.useDefaultCredentialsSetExplicitly = true;
}
}
// <SNIP/>
}
}
#pragma warning restore 1591
Settings.Designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyService.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.2.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.WebServiceUrl)]
[global::System.Configuration.DefaultSettingValueAttribute("http://localhost:/MyService/DependentService/v1.asmx")]
public string MyService_DependentService
{
get
{
return ((string)(this["MyService_DependentService"]));
}
}
}
}
So my question is the following... What is the best way to achieve the desired result? Should I create three web references for the dependent service, one for each environment and use the Environment appSettings in the Web.config file to tell MyService which web reference to use? Or is there a way to "override" MyService.Properties.Settings.Default.MyService_DependentService in a similar manner where Web.config can be overridden by a "sub-Web.config" file?