Monday, June 05, 2006

Wsdl is great, it's like reflection for web services. As I discussed in this post, you can use it to dynamically discover and call web services at runtime. The dot net framework provides a class, 'System.Web.Services.Description.ServiceDescription' that takes a wsdl stream and provides an object model to walk the wsdl. It's really powerfull, but kinda awkward to use if you just want to get a list of web methods with their parameter names and types. Faced with this requirement last week, I put together a simple facade for the ServiceDescription class. You just create a new WebServiceInfo instance using its factory method 'OpenWsdl' and then you can iterate through all the web methods and their parameters and return parameters. Here's the NUnit test which pretty much shows how it works:

33 comments:

Hi,Cool.your code is very useful.I am searching 2 days for the web to find out 'how To extract complextype information from WSDL Documents'Finally i got it from your sample.Good Work.Congratulation.How to extract complextype such as 'Address' in the Type information which has separeate definition,like street,city,zipcode.

Hi: I have a requirement for getting all method names give the name of a webservice. So i would like to use the "www........asmx?wsdl" to query the wsdl and parse the resultant XML to get all method sigantures. Is this what this piece of code does? thanks for the inputs.

No, you are right, this code simply demonstrates passing simple values as parameters. It is far from a complete solution. Check out my comment to Abhijit above for some pointers about how to work with complex types.

Mike,How to get the complex class details (i.e. for the class which falls as input / output to any web-method), the details I am looking for are :1. Class attributes which are useful in xml-serialization2. How to perform nesting on complex types to retrieve the info. same as point 1