C# – How to include the own wsdl in the web service in C#

asmxcweb serviceswsdl

I have a .wsdl file that my web service (old asmx style) must implement. That is taken care of. When I publish the web service you can call it with ?wsdl parameter to get a generated wsdl.

How do I include my .wsdl file so that is the one that is returned instead of the generated one?

Is it possible to do with an attribute in my web service class?

Best Answer

Is it a given to stay with "old-style" ASMX? Or could you move up to WCF? That's really the most current webservice offering by Microsoft, and if you're doing something new and you're on .NET 3.0 or higher - why spend time on "old" technology?

In WCF, you could definitely define a static physical WSDL file to be used by clients connecting to your metadata endpoint (your "...?wsdl" URL). Not sure if you can do it in ASMX, too.

OK, on ASMX / .NET 2.0, you could of course always put the actual WSDL file under the root of your web site, and then just reference it like this:

http://yourwebserver/YourVirtDir/MyService.wsdl 

I don't know if there's a way to "redirect" the

http://yourwebserver/YourVirtDir/MyService.asmx?wsdl 

call to go to that fixed URL instead. I'm sure someone else will know, though!

Marc