bug with sending null elements of DataSet[] ?

M

Moe Sisko

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 ?

TIA
 
J

John Saunders

Moe Sisko said:
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;}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top