Barcelona, WEB404 and a new build of the SDK

I still have almost 2 hours until my session on ASP.NET Web Services (ASMX) internals at 18:15 in Room 7. I am going to talk mostly about extensibility and about writing custom "reflectors" (which let you tweak the WSDL spit out by ASMX) and "importers" (which let you tweak the code emitted by 'Add Web Reference'). For a change, I will basically start with a blank project and implement a complete SoapExtension with Reflector and Importer live (I had a canned sample in Dallas) and then show a couple of other goodies that are in the newtelligence SDK bag. 

I just put build 2.2.3173.0 of the newtelligence SDK onto our download site. Read the readme first and then download the MSI file to install the SDK, if you are interested. I will likely show the schema extensions, management extensions and session extensions.

The schema extensions are actually a new thing that I've implemented a couple of weeks ago. The SchemaTypeReflector class tweaks the schema that's being emitted into the WSDL by ASP.NET so that it turns this class definition (if the class is used as a parameter to a web method):

[Serializable]

[System.Xml.Serialization.XmlTypeAttribute(
Namespace="urn:newtelligence-com:samples:northwind:purchaseorder:v1")]

public class orderType

{

public int OrderNumber;

[Match(@"[A-Z]+"), MaxLength(5)]

public string CustomerCode;

public System.DateTime OrderDate;

public System.DateTime RequiredDate;

[System.Xml.Serialization.XmlIgnoreAttribute()]

public bool RequiredDateSpecified;

[Match(@"\p{L}[\p{L}\p{P}0-9\s]*")]

[MaxLength(40)]

public string ShipName;

[Match(@"\p{L}[\p{L}\p{P}0-9\s]*")]

[MaxLength(60)]

public string ShipAddress;

 

...

 

 

}

into a schema type definition like this:

<s:complexType name="orderType"> 
- <s:sequence>
  <s:element minOccurs="1" maxOccurs="1" name="OrderNumber" type="s:int" />
- <s:element minOccurs="0" maxOccurs="1" name="CustomerCode">
- <s:simpleType>
- <s:restriction base="s:string">
  <s:pattern value="[A-Z]+" />
  <s:maxLength value="5" />
  </s:restriction>
  </s:simpleType>
  </s:element>
  <s:element minOccurs="1" maxOccurs="1" name="OrderDate" type="s:dateTime" />
  <s:element minOccurs="0" maxOccurs="1" name="RequiredDate" type="s:dateTime" />
- <s:element minOccurs="0" maxOccurs="1" name="ShipName">
- <s:simpleType>
- <s:restriction base="s:string">
  <s:maxLength value="40" />
  <s:pattern value="\p{L}[\p{L}\p{P}0-9\s]*" />
  </s:restriction>
  </s:simpleType>
  </s:element>
- <s:element minOccurs="0" maxOccurs="1" name="ShipAddress">
- <s:simpleType>
- <s:restriction base="s:string">
  <s:maxLength value="60" />
  <s:pattern value="\p{L}[\p{L}\p{P}0-9\s]*" />
  </s:restriction>
  </s:simpleType>
  </s:element>
- </s:complexType>

The SchemaTypeReflector will walk the type graph of all the parameters passed as an argument. Along with the reflector there is a validator extension that will either do a schema validation on the incoming XML or will check the arguments when they have already been deserialized.  That code is included in the package; check the Source directory in the installation path and look for newtelligence.Web.Services.Schema. For the reflector to work, the type newtelligence.Web.Services.Schema.SchemaTypeReflector must be added to the configuration/system.web/webServices/soapExtensionReflectorTypes section in the web.config.

Having strong contracts with schemas like this makes (amongst many other advantages) for a great combination with InfoPath 2003 since InfoPath honors schema restrictions and puits red squares around editboxes for which the restriction facets are being violated.

Updated: