Custom WSDL for an ASMX Web Service
Is it possible to use a custom WSDL with a .NET WebService? I would like to use a custom WSDL with my .NET W开发者_运维技巧ebService instead of the one generated by .NET as part of my WebService.
Actually there is a way to do this: You can create your own WSDL (i.e. removing methods you don't want to publish) and then make it available at a dedicated spot, this allows users to bind to it as normal.
To prevent users from just retrieving the default WSDL (foo.asmx?wsdl
) you have to flip a switch in the web.config of your web service:
<webServices>
<protocols>
<remove name="Documentation"/>
</protocols>
</webServices>
From the relevant MSDN section:
Note Removing the Documentation protocol also disables WSDL file generation for any XML Web services within the Web application. This prevents clients from generating a proxy class unless a custom WSDL file is created and provided for them.
I presume that what you want is to replace the file generated by .NET when your service is hit with the "?wsdl" query string on it.
No, there is no direct way to do this. Instead, simply place your .wsdl on a web site, and tell the consumers of your service to get it from there. There is no standard saying that "?wsdl" is the only way to get a WSDL file.
精彩评论