SoapExtensionReflector

Scott Short has an article on importing external schemas into your WSDL in the latest MSDN magazine. The text isn’t online yet, but you can download the code, which is the important part. The idea is that you can add attributes onto parameters and return values from your method. The attribute identifies a schema to associate with the parameter. I don’t think it provides validation, but that would be easy enough to add via a SoapExtension. The framework uses the semi-documented System.Web.Services.Description.SoapExtensionReflector class to modify the default WSDL generated by the .NET framework, so your WSDL contains the complete contract for the method, but internally, you’re dealing with the data as XML.  [Gordon Weakliem’s Radio Weblog]

This is super-cool.  With this code, you can create a method taking a XmlNode parameter, but have it strongly typed in your WSDL:

[WebMethod]
public int Test(
   [XmlImportedElement(“urn:test”, “test.xsd”, ElementName=”Stuff”)]
   XmlNode stuff)
{}

So on the server side, we can process the parameter as XML; and yet the contract is fully described (including schema) in the auto-generated WSDL.  Tim Ewald talked about this kind of thing at the DevCon – great stuff.

Nice job, Scott!

Leave a Reply