Despite all the SO(A)-iness out there we sometimes just want or simply need to ignore it.
One of those topics is the good old DataSet. There is lot of trouble when you use it and you do not know all the problems and side effects it may cause. But in some certain scenarios, it might just be fine. Consider the following sample contract for an Indigo service.
[ServiceContract(Session = true)]
public interface IWantIt
{
[OperationContract()]
DataSet GetData(string ID);
}
A very common and often used pattern. Usually this should work just fine. ASMX does handle it quite well. But if we build an application which hosts an Indigo service that implements this contract we will get a runtime error – it builds fine, yes. Why?
Indigo is using the XmlFormatter class by default. XmlFormatter does not support non-data contract schema. And using a System.Data.DataSet type means breaking with the data contract rules. However there is support for non-data contract schema using good plain old XmlSerializer.
With the following updated ServiceContracteverything should work as expected.
[ServiceContract(Session = true, FormatMode = ContractFormatMode.XmlSerializer)]
public interface IWantIt
{
[OperationContract()]
DataSet GetData(string ID);
}
Again, this does not mean that you are supposed to use DataSets in your contract… J