How can I dynamically switch web service addresses in .NET without a recompile?

后端 未结 11 963
小蘑菇
小蘑菇 2020-11-28 09:11

I have code that references a web service, and I\'d like the address of that web service to be dynamic (read from a database, config file, etc.) so that it is easily changed

11条回答
  •  难免孤独
    2020-11-28 09:37

    open solition explorer

    right click the webservice change URL Behavior to Dynamic

    click the 'show all files' icon in solution explorer

    in the web reference edit the Reference.cs file

    change constructer

    public Service1() {
            this.Url = "URL"; // etc. string  variable this.Url = ConfigClass.myURL
          }
    

提交回复
热议问题