Re: bug with sending null elements of DataSet[] ?



"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

.



Relevant Pages

  • Re: Remote control with TcpListener
    ... Your server code blocks on the call to read 65535 bytes of data. ... about parsing the command that the client has sent you. ... of strings to represent the commands. ... public int ...
    (microsoft.public.dotnet.languages.csharp)
  • Tuning the performance of ObjectInputStream.readObject()
    ... I'm using JWorks, which roughly corresponds to jdk1.1.8, on my client ... and jdk1.4.2 on the server side ... Vxworks) and deprive other threads, including non-Java ones, for this ... public int readthrows IOException { ...
    (comp.lang.java.programmer)
  • RE: Calling COM Server from ASP.NET WebService - impersonation pro
    ... is a COM+ server luckily) it works! ... I want to call a COM+ server from a webservice. ... and check the current User it is the client as it should be. ... I thought that would happen automatically since the webmethod is ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Java
    ... if you want the server to handle multiple clients, ... should I have a client class, server class, and connection class?? ... a client class and a server class makes a lot of sense. ... public int receive{ ...
    (comp.lang.java.help)
  • Re: Java
    ... if you want the server to handle multiple clients, ... should I have a client class, server class, and connection class?? ... a client class and a server class makes a lot of sense. ... public int receive{ ...
    (comp.lang.java.databases)