11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12: Building Secure <strong>Web</strong> Services 329using System.Xml;using System.Xml.Schema;[<strong>Web</strong>Method]public void OrderBooks(string xmlBookData){try{// Create <strong>and</strong> load a validating readerXmlValidatingReader reader = new XmlValidatingReader(xmlBookData,XmlNodeType.Element,null);// Attach the XSD schema to the readerreader.Schemas.Add("urn:bookstore-schema",@"http://localhost/WSBooks/bookschema.xsd");// Set the validation type for XSD schema.// XDR schemas <strong>and</strong> DTDs are also supportedreader.ValidationType = ValidationType.Schema;// Create <strong>and</strong> register an event h<strong>and</strong>ler to h<strong>and</strong>le validation errorsreader.ValidationEventH<strong>and</strong>ler += new ValidationEventH<strong>and</strong>ler(ValidationErrors );// Process the input datawhile (reader.Read()){. . .}// Validation completed successfully}catch{. . .}}// Validation error event h<strong>and</strong>lerprivate static void ValidationErrors(object sender, ValidationEventArgs args){// Error details available from args.Message. . .}The following fragment shows how the consumer calls the preceding <strong>Web</strong> method:string xmlBookData = "" +"Building Secure ASP.NET <strong>Application</strong>s" +"0735618909" +"1" +"";BookStore.BookService bookService = new BookStore.BookService();bookService.OrderBooks(xmlBookData));

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!