I am attempting to create a Web service which returns a dataset (or even an XML document) that is valid against a particular schema. The schema only has a top element, say, Employees and multiple Employee elements inside which contain elements for name,
email, telephone. ID is the only attribute to the Employee element. I am attempting to fill the dataset and return the dataset (or an XML document) to the client.
I have tried to create a dataset from the schema using the XmlReadSchema, and then create a dataadapter that fills the table in the dataset. During debugging, it appears that the datatable gets created, the dataadapter fetches the data but if I fill to the
table created by the XmlReadSchema, it causes an error:
System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
If I look at the Constraints collection, the count = 0. If I fill a new table name "on the fly" (da.fill(ds, "DifferentTable")) it fills the dataset. I am returning a single row from the database in a table and with data specifically
made to conform to the schema. I have done some reading, and I think a WCF solution is a direction I should go, but I need to provide solutions while I learn WCF.
What would be the best way to ensure that the data I return from an SQL Server table goes out the Web service formatted according to a particular schema?
(Note: I did review an article
on Extending WebMethods with Schema Validation from a 2003 July article, but could not see the ValidationExtension type in the current .NET.)
Thank you for your advice.