Protect .net Web Service URL

2019-04-09 15:09发布

问题:

I have created Web Service using Asp.net 3.5. Now it's working perfectly in live windows server, and giving me perfect xml while invoking it using some url like :

http://www.somedomain.com/Service.asmx?op=fetchData

Now My question is when I am accessing url like :

http://www.somedomain.com/Service.asmx

it's listing my created web services.

What if I don't wanna list down the available web services to end users.

Thanks in advance...

回答1:

If you just want to disable the service help page then add the following to the system.web section of web.config:

<webServices>
   <wsdlHelpGenerator href="HideServices.aspx"/>
</webServices>

where HideServices.aspx is a page that contains the content you want to display when someone tries to browse http://www.somedomain.com/Service.asmx (it could be blank or a generic message).

The above config does leave WSDL generation enabled via ?WSDL (http://www.somedomain.com/Service.asmx?WSDL). If you also don't want to serve up your WSDL then instead add the following to the system.web section of web.config:

<webServices>
  <protocols>
    <remove name="Documentation" />
  </protocols>
</webServices>