what's the best way to pass XML document as a remoting argument?

dotnet framework

what's the best way to pass XML document as a remoting argument?

Postby Keith Langer » Thu, 26 Oct 2006 10:57:06 GMT


I'm looking for the most efficient way to pass an XML document into a
remoting call.  I know that I can return an XMLDocument from a remoting
call, but passing one as an argument causes errors.  If I pass the XML
as a string, I believe that all tags will get URL-encoded, making the
document much bigger.  I supposed that I could base64 encode it.  Is
there a way to just pass it as straight binary data?

Keith Langer

Re: what's the best way to pass XML document as a remoting argument?

Postby Gter Prossliner » Thu, 26 Oct 2006 19:08:45 GMT


Because the XML-Document is not derived by MarshalByRef object and not 
serializable you cannot pass it through remoting directly.

This depends on the kind of formatter you use. A Xml / Soap Formatter MAY 
encode the XML-String. A binary formatter does not.

This depends on the formatter. The Binary Formatter can do it (others can 
also do it, but the data may be encoded in most cases (depends on the 

If you have to deal with really "big" xml-files, and you can control both 
the client and the server, it may be an option for you to use some kind of 
compression (like GZipStream). Because XML is very redundant GZIP will 
compress the data very well.


// compress
XmlDocument doc = ...;
MemoryStream ms = new MemoryStream();
GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress);

byte[] compressed = ms.ToArray();

MemoryStream ms = new MemoryStream(data);
GZipStream zipStream = new GZipStream(ms, CompressionMode.Decompress);



Re: what's the best way to pass XML document as a remoting argument?

Postby Keith Langer » Thu, 26 Oct 2006 22:11:19 GMT


The documents are about 100K, so there's probably not a lot of need for
compression (I'd be trading bandwidth for CPU time to compress and
deflate).  I tested one of these documents and found that URLEncode
expands it by about 50%, as opposed to 33% for base64.  That's probably
not a huge deal.  What exactly happens with binary encoding, and how
does it affect the document size?  Do you have a good example of using
binary encoding?

Is there a way to see exactly what gets passed via the remoting call
and determine its size?


Re: what's the best way to pass XML document as a remoting argument?

Postby Gter Prossliner » Sat, 28 Oct 2006 16:59:11 GMT

Hi Keith!

The question is: What restricts you more? The CPU or the bandwidth?

URLEncode from what? Binary data??? URL Encoding a string should not expand 
the size by 50%.

What do you meen with "Binary Encoding"? BinaryFormatting?

This depends on the way remoting is configured for you application / object. 
When you use a TcpChannel, the binary-Formatter is choosen by default.

You can use tools like etherreal for this. If you want to determinate the 
size of a single object, you can serialize the instance into Memory 
(BinarySerializer / MemoryStream), and check out how much memory is used.


Similar Threads:

1.Passing arrays arguments using remoting versus calling directly

Can someone verify this for me?

A function like: public Foo(Byte [] someArray) { someArray[0] = 1;  }

If Foo is called directly from within the assembly the caller's passed aray 
will be affected by the call.  However, if the object is exposed via .Net 
remoting and Foo is then called remotely, the caller's passed array will not 
be affected unless Foo is changed to: public Foo(ref Byte [] someArray) { 
someArray[0] = 1;  }

In other words, an additional level of referencing/dereferencing is required 
when using remoting.  If this is true, is it also true for other reference 

Ralph Flaugher

2.What's the best practice to pass dataset object?


I am looking for best practice on passing dataset object around, should it
be passed by reference or by value. What gives the best performance, how
does it works internally when you pass by value?

Please advice, thanks

3.Locating xmlns nodes in XML documents (for XML document metrics)

I've been writing an XML document analyzer that reads XML document
and tracks the metrics of the document. Statistics such as a node count fo
each type of XML node are printed out

I am trying to locate 'xmlns' nodes using the XPath (not DOM or SAX) API
Unfortunately the XPathNavigator concept of namespace nodes for eac
element is only accessible via MoveToFirstNamespace() an
MoveToNextNamespace().  The XPath model constructs a namespace node lis
for EACH ELEMENT where each namespace node represents a namespace CURRENTL
IN SCOPE for the current XML node

I would like to easily locate the 'xmlns' references in an XM
document just to count them and optionally print them out. It woul
also be nice to track some namespace node statistics such as defaul
vs prefix namespace declarations

Does anyone have an idea on how to do this

4.How to handle an XML document within an XML document

C#, .NET 1.0

I use XML serialisation to persist state of object definitions.One of my
objects wraps up a 3rd party object (non .NET) which can only serialise
itself to a file. However, it's needed that the parent wrapper object
includes all state data in one file so I need to include the 3rd party
serialisation file into the main file.

I'm trying to do this at present by reading the content of the file using a
StreamReader object, then into a string using ReadToEnd().

There are two problems:
1) I need a public property so that the XML Serialiser will manage the
string during de/serialisatin.I have no need for the property other than for
2) The content of the string is a full XML document (i.e. it contains the
'<? xml> root). This has caused me issues later on as on deserialisation -
although I don't use the full document, I need to have a subset of the nodes
from this object as a proper XML document (I execute some XSL over these in
order to generate some reports on the data).

I'd appreciate any help on the correct way of implementing this. I can live
with the public property, it's important to get the XML document for the
wrapped object into something I can use!

Many thanks in advance!

5.Passing XMLSchema object using Remoting.


I am using .NET Remoting in a client server environment, and I have
to pass an XmlSchema object to the client using remoting. As this
class (XmlSchema) doesn't extend MarshalByRefObject and not
even serializable, what could be a work around for the same ?

best regards

6. Why can't an XmlDocument be passed via remoting?

7. Remoting: How to best pass data across tiers

8. Best practices for passing data over remoting

Return to dotnet framework


Who is online

Users browsing this forum: No registered users and 97 guest