How do I change a web reference in a production .NET website?

前端 未结 2 1499
轮回少年
轮回少年 2021-02-20 05:17

Our web reference does not seem to be defined in web.config of the website that consumes it. I found that there is a configuration file called \"Reference.map\" in the \"Web Ref

相关标签:
2条回答
  • 2021-02-20 05:26

    You can mark a web reference as static or dynamic URL. If you choose dynamic then it will add the URL to the web.config which you can then change in your production environment.

    If it is marked as static then it is compiled into the binary and is not changeable without a rebuild.

    If it is already dynamic then the code looks for the dynamic URL and then if it can't find it then it uses the default original. Therefore, you can just add an entry into the web config such as:

    <applicationSettings>
        <MySystem.Properties.Settings>
            <setting name="MySystem_MyService" serializeAs="String">
                <value>http://mysystem/service.asmx</value>
            </setting>
        </MySystem.Properties.Settings>
    </applicationSettings>
    
    0 讨论(0)
  • 2021-02-20 05:40

    On Compact Framework you have to read the config file on your own class of WebService:

    public partial class YourService : System.Web.Services.Protocols.SoapHttpClientProtocol {
    
        /// <remarks/>
        public HandTerminalService() {
            string appSettings = string.Concat(Assembly.GetExecutingAssembly().GetName().CodeBase, ".config");
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(appSettings);
            XmlNode xmlNode = xmlDocument.SelectSingleNode("//configuration/appSettings/add[@key = 'Proxy.YourServiceService']");
            if (xmlNode.Attributes["value"].Value != null)
            {
                this.Url = string.Concat(xmlNode.Attributes["value"].Value, "");
            } else
            {
                this.Url = "http://<IP_or_DNS-Name>:<Port>/YourService.asmx";
            }
        }
    
    0 讨论(0)
提交回复
热议问题