WebMethod [Validation] and [Assert] Attributes

Service Station, by Aaron Skonnard

Syndication

This sample illustrates how to write a SoapExtension for enabling XML Schema validation on incoming SOAP messages. You can turn on validation by using the [Validation] attribute as illustrated here:

...
[Validation]
[WebMethod]
public double Add(double x, double y) {
     return x+y;
}

The validation occurs against the XML Schema generated by the .asmx infrastructure by default, although you can point the extension to your custom schema if you desire.

In addition to XML Schema validation, this extension provides support for validating arbitrary XPath assertions as illustrated here:

...
[Assert(“//l > //w“)]
[Validation]
[WebMethod]
public double CalcDistance(double l, double w) {
     return l*w;
}

This indicates that the length must be greater than width, an assertion you cannot express with XML Schema (note: you may have to use namespace prefixes depending on your WebMethod configuration).

For details of how this sample works and the functionality it provides, check out my following articles:

Download here.


Posted Jan 30 2004, 04:56 AM by Aaron Skonnard
Filed under:

Comments

The XML Files wrote MessagePredicate Policy Handler
on 01-30-2004 7:39 AM
The XML Files wrote MessagePredicate Policy Assertion Handler
on 01-30-2004 7:40 AM
The XML Files wrote MessagePredicate for Validation
on 02-05-2004 1:07 AM
The XML Files wrote MessagePredicate for Validation
on 02-05-2004 1:13 AM
John Bristowe's Weblog wrote COOL: MessagePredicate Validation in WSE v2.0 TP (Aaron Skonnard)
on 02-05-2004 11:05 AM

Add a Comment

(required)  
(optional)
(required)  
Remember Me?