Hide asmx web methods conditionally in C#

后端 未结 2 1008
独厮守ぢ
独厮守ぢ 2021-01-22 23:57

How can I conditionally hide the web methods? I don\'t want to expose the web method if a flag setup in web.config is false. If it is true, then I will expose the web method.

2条回答
  •  不思量自难忘°
    2021-01-23 00:17

    You can't really do this.

    Your clients "see" the web methods because they are listed in the WSDL. The WSDL generation is fairly static - it is based on the [WebMethod] attributes on your methods. There is really no ability to remove items from the generated WSDL.

    If you can switch to WCF, you will find this much, much, easier. In the meantime, you'll just have to use authorization - prevent some clients from calling some methods.

提交回复
热议问题