Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / June 2004

Tip: Looking for answers? Try searching our database.

Passing datasets through remoting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ariel Popovsky - 27 Jun 2004 15:50 GMT
Hi!

I'm having a problem passing a dataset to a method through remoting. If I
call one method from the client application and pass a dataset to it, when
it returns the dataset is empty. This happens only when I use remoting,
calling the method locally works fine.

I've been testing this issue using a server application with three different
methods.
1. public DataSet GetDataSet(string sql): runs the sql query and returns a
new dataset with one table in it. Works fine.

2. public void GetDataSet(string sql, DataSet dataSet): runs the sql query
and adds a new table to the dataset returned by the previous method. When
this method returns, there is only one table in the dataset. When I debug it
I see that a new table is being added but not passed back. The dataset
behaves like a value type here.

3. public void GetDataSet(string sql, ref DataSet dataset). This method just
calls the previous one. When the client app calls this method the dataset
returns with the new table in it.

If I do the same thing using a serializable business object, everything
works fine and I don't need to mark the parameter as "ref".

If someone could help me undestand this odd behaviour I'll be very
gratefull.

Thanks!
---------------------
Ariel Popovsky
Buenos Aires, Argentina
Sahil Malik - 27 Jun 2004 16:12 GMT
Can you paste the code for

public DataSet GetDataSet(string sql):

and

public void GetDataSet(string sql, DataSet dataSet):

?

- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/

> Hi!
>
[quoted text clipped - 28 lines]
> Ariel Popovsky
> Buenos Aires, Argentina
Ariel Popovsky - 27 Jun 2004 18:53 GMT
Sure!
In the client I call the first method and then pass the same dataset to all
the rest.

public DataSet GetDataSet(string sql)
 {
  DataSet dataSet=new DataSet();
  using(OracleConnection connection=new OracleConnection("...."))
  {

   connection.Open();
   OracleDataAdapter adapter=new OracleDataAdapter(sql, connection);
   adapter.Fill(dataSet, "A");
   return dataSet;
  }
 }

 public void GetDataSet(string sql, DataSet dataSet)
 {
  if(dataSet==null) throw new ArgumentNullException("dataset", "que
hace!!");
  using(OracleConnection connection=new OracleConnection("..."))
  {
   connection.Open();
   OracleDataAdapter adapter=new OracleDataAdapter(sql, connection);
   adapter.Fill(dataSet, "B");
  }
 }

 public DataSet GetDataSet(DataSet dataSet, string sql)
 {
  if(dataSet==null) throw new ArgumentNullException("dataset", "que
hace!!");
  using(OracleConnection connection=new OracleConnection("..."))
  {
   connection.Open();
   OracleDataAdapter adapter=new OracleDataAdapter(sql, connection);
   adapter.Fill(dataSet, "C");
  }

  return dataSet;
 }

 public void GetDataSet(string sql, ref DataSet dataset)
 {
  GetDataSet(sql, dataset);
 }

> Can you paste the code for
>
[quoted text clipped - 46 lines]
> > Ariel Popovsky
> > Buenos Aires, Argentina
Ken Kolda - 28 Jun 2004 18:17 GMT
The DataSet is a serializable, non-MarshalByRefObject-derived class so when
it crosses the remoting layer it gets serialized/deserialized and the
receiving end has its own copy (as if it were a value type). Thus, changes
to the object will not be seen by the caller unless, as you noted, you mark
the parameter with "ref" or "out" (which tells the remoting interfaces to
remote the object back when the call completes).

Do your business objects derive (directly or indirectly) from
MarshalByRefObject? If so, that would explain why they work as you expect --
but it also means that every property/method call is crossing the remoting
channel (could be expensive if it's not what you intend).

Ken

> Sure!
> In the client I call the first method and then pass the same dataset to all
[quoted text clipped - 101 lines]
> > > Ariel Popovsky
> > > Buenos Aires, Argentina
Ariel Popovsky - 29 Jun 2004 00:31 GMT
I thought something like that, I believe it has to be something about the
way DataSets are serialized. Maybe it get passed as plain XML (BTW, I'm
using a BinaryFormatter through a tcp channel).
My business object is very simple, just a couple of fields and it doesn't
extend any other class. It's just marked with the SerializableAttribute.

Thanks for the answers!
Ariel

> The DataSet is a serializable, non-MarshalByRefObject-derived class so when
> it crosses the remoting layer it gets serialized/deserialized and the
[quoted text clipped - 9 lines]
>
> Ken
Ken Kolda - 29 Jun 2004 01:35 GMT
You're saying you can pass a serializable business object to a remote system
without using "ref" or "out" and the caller can see the changes made to the
object? That goes against how I understand that remoting works -- you may
want to verify this behavior before you build to much dependence on this
behavior.

A couple of other things to note:

1. The DataSet does serialize itself as XML, but that's really
inconsequential to what you're seeing. The manner in which the object is
serialized (whether it just uses the default serialization provided by
[Serializable] or implements its own using ISerializable) has no effect on
whether you will see changes made in the remoted object. Any object that's
not MBR and is serializable will be passed with value-type sematics across
remoting interfaces.

2. The formatter/channel also make no difference to the logical sematics of
remoting. The DataSet will serialize itself to XML regardless of the
channel/formatter type being used -- it doesn't know or care what type of
envelope the remoting infrastructure is going to wrap it in. Using a binary
formatter just means that once the DataSet generates its XML, it is binary
encoded along with the remoting header info and sent across the wire. If you
were using SOAP, the XML would be wrapped in a SOAP-formatted package.
Either way, the formatter on the other end knows how to restore the XML to
its original form so that when the DataSet deserializes it has the correct
data.

Ken

> I thought something like that, I believe it has to be something about the
> way DataSets are serialized. Maybe it get passed as plain XML (BTW, I'm
[quoted text clipped - 21 lines]
> >
> > Ken
Ariel Popovsky - 30 Jun 2004 00:01 GMT
You were right Ken, there was an error in my test application. I was writing
to the console some field values from the server, where the BO was modified
and not from the client after the method returned. I added a new output to
the client and found that the behaviour is consistent, when I use ref, the
modifications made by the server can be seen in the client, otherwise they
don't.

Thanks!
Ariel

> You're saying you can pass a serializable business object to a remote system
> without using "ref" or "out" and the caller can see the changes made to the
[quoted text clipped - 53 lines]
> > >
> > > Ken

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.