Re: bug with sending null elements of DataSet[] ?
- From: "John Saunders" <no@xxxxxxxxxxxxxxxx>
- Date: Thu, 9 Oct 2008 09:38:31 -0400
"Moe Sisko" <null> wrote in message news:OY3yK0dKJHA.5336@xxxxxxxxxxxxxxxxxxxxxxx
Using dotnet : 2.0.50727.1433
To reproduce problem :
On server side :
==
[WebMethod]
public void SendDataSetArray(DataSet[] ds)
{
string str = "ds[0] is null ? : " + (ds[0] == null).ToString(); // XXX
}
==
On client side, call webmethod like this :
==
DataSet[] ds = new DataSet[1];
ds[0] = null;
ws.SendDataSetArray(ds);
==
where : ws is an instance of the web proxy object.
So, on server side, I expected to see a DataSet array with one element, where that element contains null.
However, I'm seeing a DataSet array with one element, where that element is an empty DataSet (non-null !) which contains zero DataTables.
i.e. str at line XXX gets set to : "ds[0] is null ? : False"
Does this look like a bug, or am I missing something ?
Yes. This looks like a bug. I just tried this, and watched the traffic in Fiddler. The null element is being sent back as:
<DataSet xsi:nil="true" /><DataSet>
This should have been a big hint to the client, but apparently, it was not. You could report this as a bug on Connect, at http://connect.microsoft.com/visualstudio/.
On the other hand, I've said for quite a while that returning DataSet, DataTable, or other .NET-specific types is a bad practice. These platform-specific types are (no surprise) not interoperable. This experiment has made it even clearer to me why that is. Take a look at how an empty, but non-null DataSet is serialized:
<DataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" />
</DataSet>
What is some other platform supposed to do with _that_ mess? Sending the schema along with the data is non-standard. Expecting any other platform to understand a diffgram is just plain silly.
Instead of returning a DataSet, just return the data. Use your own Data Transfer Object (DTO) class that has one property per table in your DataSet. Each such property returns a collection of a "row" class. That class would have one property per column of the corresponding DataRow:
namespace DTONamespace
{
public struct DataSetDTO
{
public List<Table1RowDTO> Table1{get;set;}
public List<Table2RowDTO> Table2{get;set;}
}
public struct Table1RowDTO
{
public int ID{get;set;}
public string Name{get;set;}
}
public struct Table2RowDTO
{
public int ID{get;set;}
public string Address{get;set;}
public int Table1FK{get;set;}
}
}
--
John Saunders | MVP - Connected System Developer
.
- References:
- bug with sending null elements of DataSet[] ?
- From: Moe Sisko
- bug with sending null elements of DataSet[] ?
- Prev by Date: Re: Displaying an ActiveX
- Next by Date: Web Service as a background service
- Previous by thread: bug with sending null elements of DataSet[] ?
- Next by thread: Displaying an ActiveX
- Index(es):
Relevant Pages
|