473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Passing xml vs. passing a class

There are two ways to pass structured data to a web service:

xml
===

<Order OrderId="123" OrderAmount="234" />

or class
=====

public class Order
{
public string OrderId;
public deciaml OrderAmount;
}

Class will be serialized to xml and on soap level there will be no
difference.

Are there any white paper or any guideline document which compares these two
methods? In which cases should I use one or another?

For example, test page is not available when passing a class, but xml is
used, I can make it Notepad and paste it into the test page.
Thanks,

-Stan
Nov 23 '05 #1
10 3443
Stan,

I don't think there is any whitepaper on the above. The classes you use in
WebServices are nothing but state objects -- with Get/Set properties. Hence,
they can be represented as XML (for the structured data). Passing objects
instead of XMl makes it easier to play with the data on the either side --
else you will have to use XML parsers to get values; I would almost always
prefer a class.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
There are two ways to pass structured data to a web service:

xml
===

<Order OrderId="123" OrderAmount="234" />

or class
=====

public class Order
{
public string OrderId;
public deciaml OrderAmount;
}

Class will be serialized to xml and on soap level there will be no
difference.

Are there any white paper or any guideline document which compares these two methods? In which cases should I use one or another?

For example, test page is not available when passing a class, but xml is
used, I can make it Notepad and paste it into the test page.
Thanks,

-Stan

Nov 23 '05 #2
I prefer using classes also. The only comment and if somebody has
actually tested this and found this to be true or not to be true feel
free to comment, would make that for speed create your own
serialization/deserialization methods. since implementing the
ISerialization interface and implementing the constructor allows .net
to not use reflection when serializaing data to xml or any other format?

Nov 23 '05 #3
There are two benefits of xml I can think of:

1. Predictable xml format. Not relying on xml serialization
2. Easy to test

I don't think it is hard to change or get anything:

XmlDocument doc = new XmlDocument();
doc.LoadXml (xml);
string OrderId = doc.SelectSingleNode ("//OrderId").Value:

It is longer than

string OrderId = Order.OrderId;

but not a huge deal..

"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
Stan,

I don't think there is any whitepaper on the above. The classes you use in
WebServices are nothing but state objects -- with Get/Set properties. Hence, they can be represented as XML (for the structured data). Passing objects
instead of XMl makes it easier to play with the data on the either side --
else you will have to use XML parsers to get values; I would almost always
prefer a class.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
There are two ways to pass structured data to a web service:

xml
===

<Order OrderId="123" OrderAmount="234" />

or class
=====

public class Order
{
public string OrderId;
public deciaml OrderAmount;
}

Class will be serialized to xml and on soap level there will be no
difference.

Are there any white paper or any guideline document which compares these

two
methods? In which cases should I use one or another?

For example, test page is not available when passing a class, but xml is
used, I can make it Notepad and paste it into the test page.
Thanks,

-Stan


Nov 23 '05 #4
Stan,

Totally agree... however, now consider:

string myName = Order.Orders[5].Customer.CustomerName;

It makes it not only shorter, but also logical instead of say
"//orders[@id=5]/Customer/@CustomerName"

However, putting my consulting hat on, the solution does not fit all cases.
Given some performance hit during serialization/de-serialization, and given
the ability to scale well, I could choose the XML approach.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
There are two benefits of xml I can think of:

1. Predictable xml format. Not relying on xml serialization
2. Easy to test

I don't think it is hard to change or get anything:

XmlDocument doc = new XmlDocument();
doc.LoadXml (xml);
string OrderId = doc.SelectSingleNode ("//OrderId").Value:

It is longer than

string OrderId = Order.OrderId;

but not a huge deal..

"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
Stan,

I don't think there is any whitepaper on the above. The classes you use in WebServices are nothing but state objects -- with Get/Set properties.

Hence,
they can be represented as XML (for the structured data). Passing objects instead of XMl makes it easier to play with the data on the either side -- else you will have to use XML parsers to get values; I would almost always prefer a class.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
There are two ways to pass structured data to a web service:

xml
===

<Order OrderId="123" OrderAmount="234" />

or class
=====

public class Order
{
public string OrderId;
public deciaml OrderAmount;
}

Class will be serialized to xml and on soap level there will be no
difference.

Are there any white paper or any guideline document which compares these
two
methods? In which cases should I use one or another?

For example, test page is not available when passing a class, but xml

is used, I can make it Notepad and paste it into the test page.
Thanks,

-Stan



Nov 23 '05 #5
Here is one important benefit of xml - inteface is stable. In other words if
I have

SendOrder (string xml)

I can pass anything (which is good and bad at the same time), and it is
easier to change withought regenerating proxy classes for all clients...

"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:OM**************@TK2MSFTNGP10.phx.gbl...
Stan,

Totally agree... however, now consider:

string myName = Order.Orders[5].Customer.CustomerName;

It makes it not only shorter, but also logical instead of say
"//orders[@id=5]/Customer/@CustomerName"

However, putting my consulting hat on, the solution does not fit all cases. Given some performance hit during serialization/de-serialization, and given the ability to scale well, I could choose the XML approach.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
There are two benefits of xml I can think of:

1. Predictable xml format. Not relying on xml serialization
2. Easy to test

I don't think it is hard to change or get anything:

XmlDocument doc = new XmlDocument();
doc.LoadXml (xml);
string OrderId = doc.SelectSingleNode ("//OrderId").Value:

It is longer than

string OrderId = Order.OrderId;

but not a huge deal..

"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
Stan,

I don't think there is any whitepaper on the above. The classes you
use
in WebServices are nothing but state objects -- with Get/Set properties. Hence,
they can be represented as XML (for the structured data). Passing objects instead of XMl makes it easier to play with the data on the either side -- else you will have to use XML parsers to get values; I would almost always prefer a class.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
> There are two ways to pass structured data to a web service:
>
> xml
> ===
>
> <Order OrderId="123" OrderAmount="234" />
>
> or class
> =====
>
> public class Order
> {
> public string OrderId;
> public deciaml OrderAmount;
> }
>
> Class will be serialized to xml and on soap level there will be no
> difference.
>
> Are there any white paper or any guideline document which compares these two
> methods? In which cases should I use one or another?
>
> For example, test page is not available when passing a class, but
xml is > used, I can make it Notepad and paste it into the test page.
>
>
> Thanks,
>
> -Stan
>
>



Nov 23 '05 #6
I fail to see how that example pertains to the question however.
AbridgedTicketInfo[] MyWebMethod()
{ return GetListOfTickets(); }

This web service method returns XML regardless of how it was created.
I thought what Stan was originally asking was how to constfuct it.
e.g.
XmlNode TmpNode = RootDocument.CreateElement("order");
XmlAttribute TmpAttr = RootDocument.CreateAttribute("orderid");
TmpAttr.Value = OrderID.ToString();
RootDocument.Append(TmpNode);
TmpNode.Append(TmpAttr);

versus
[Serializable
public class OrderInfo : ISerializable
{
// implementation of Iserialization GetInfo and Constructor
can goes here for improved performance
}

Both methods return Xml.
One requires lots of extra code to construct every single node and
attribute.
One merely requires implementing a proxy class for the serialization.

How one chooses to use the data upon consuming it is one's own choice.
One could use it as raw xml - because both methods return Xml or one
could choose to deserialize the xml into an array of OrderInfo.

Nov 23 '05 #7
It is similar to:

SendOrder (object myClass)

-- not any different (beside the overhead of casting). The compromise
between a stable interface and a concrete one is always the
readability/logical view. Not saying one is better, but I guess your
software has to stabilize at some point, especially if you wish the outside
world can have a contract with it. Besides, you could version your
interfaces so different clients can be served differently.
--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:eZ**************@tk2msftngp13.phx.gbl...
Here is one important benefit of xml - inteface is stable. In other words if I have

SendOrder (string xml)

I can pass anything (which is good and bad at the same time), and it is
easier to change withought regenerating proxy classes for all clients...

"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:OM**************@TK2MSFTNGP10.phx.gbl...
Stan,

Totally agree... however, now consider:

string myName = Order.Orders[5].Customer.CustomerName;

It makes it not only shorter, but also logical instead of say
"//orders[@id=5]/Customer/@CustomerName"

However, putting my consulting hat on, the solution does not fit all

cases.
Given some performance hit during serialization/de-serialization, and

given
the ability to scale well, I could choose the XML approach.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
There are two benefits of xml I can think of:

1. Predictable xml format. Not relying on xml serialization
2. Easy to test

I don't think it is hard to change or get anything:

XmlDocument doc = new XmlDocument();
doc.LoadXml (xml);
string OrderId = doc.SelectSingleNode ("//OrderId").Value:

It is longer than

string OrderId = Order.OrderId;

but not a huge deal..

"Manohar Kamath" <mk*****@TAKETHISOUTkamath.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
> Stan,
>
> I don't think there is any whitepaper on the above. The classes you

use
in
> WebServices are nothing but state objects -- with Get/Set properties. Hence,
> they can be represented as XML (for the structured data). Passing

objects
> instead of XMl makes it easier to play with the data on the either

side --
> else you will have to use XML parsers to get values; I would almost

always
> prefer a class.
>
> --
> Manohar Kamath
> Editor, .netWire
> www.dotnetwire.com
>
>
> "Stan" <no****@yahoo.com> wrote in message
> news:%2******************@TK2MSFTNGP14.phx.gbl...
> > There are two ways to pass structured data to a web service:
> >
> > xml
> > ===
> >
> > <Order OrderId="123" OrderAmount="234" />
> >
> > or class
> > =====
> >
> > public class Order
> > {
> > public string OrderId;
> > public deciaml OrderAmount;
> > }
> >
> > Class will be serialized to xml and on soap level there will be no
> > difference.
> >
> > Are there any white paper or any guideline document which compares

these
> two
> > methods? In which cases should I use one or another?
> >
> > For example, test page is not available when passing a class, but

xml
is
> > used, I can make it Notepad and paste it into the test page.
> >
> >
> > Thanks,
> >
> > -Stan
> >
> >
>
>



Nov 23 '05 #8
The class doesn't seem to return readonly properties...Is anybody able to do
this?
Dan

"Manohar Kamath" wrote:
Stan,

I don't think there is any whitepaper on the above. The classes you use in
WebServices are nothing but state objects -- with Get/Set properties. Hence,
they can be represented as XML (for the structured data). Passing objects
instead of XMl makes it easier to play with the data on the either side --
else you will have to use XML parsers to get values; I would almost always
prefer a class.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
There are two ways to pass structured data to a web service:

xml
===

<Order OrderId="123" OrderAmount="234" />

or class
=====

public class Order
{
public string OrderId;
public deciaml OrderAmount;
}

Class will be serialized to xml and on soap level there will be no
difference.

Are there any white paper or any guideline document which compares these

two
methods? In which cases should I use one or another?

For example, test page is not available when passing a class, but xml is
used, I can make it Notepad and paste it into the test page.
Thanks,

-Stan


Nov 23 '05 #9
You can still use XML messages, and have the classes that you need. This is
more in line with SOA. Look at this great article, specifically, check out
the section on "Building an ASP.NET web service". I started using this
pattern, and it works quite well.

You define xml schemas for what you want to send to the webservice method,
and what you receive back, and then run the XSD tool that comes with VS. It
then creates the serialized classes based on your schemas. You can then use
them in your method as input variables and return values.

Here is the article:
http://msdn.microsoft.com/architectu...soiwithnet.asp

"Dan Marshall" wrote:
The class doesn't seem to return readonly properties...Is anybody able to do
this?
Dan

"Manohar Kamath" wrote:
Stan,

I don't think there is any whitepaper on the above. The classes you use in
WebServices are nothing but state objects -- with Get/Set properties. Hence,
they can be represented as XML (for the structured data). Passing objects
instead of XMl makes it easier to play with the data on the either side --
else you will have to use XML parsers to get values; I would almost always
prefer a class.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
There are two ways to pass structured data to a web service:

xml
===

<Order OrderId="123" OrderAmount="234" />

or class
=====

public class Order
{
public string OrderId;
public deciaml OrderAmount;
}

Class will be serialized to xml and on soap level there will be no
difference.

Are there any white paper or any guideline document which compares these

two
methods? In which cases should I use one or another?

For example, test page is not available when passing a class, but xml is
used, I can make it Notepad and paste it into the test page.
Thanks,

-Stan


Nov 23 '05 #10
Excellent artcle

"Le MasterChief" <Le***********@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
You can still use XML messages, and have the classes that you need. This is more in line with SOA. Look at this great article, specifically, check out the section on "Building an ASP.NET web service". I started using this
pattern, and it works quite well.

You define xml schemas for what you want to send to the webservice method,
and what you receive back, and then run the XSD tool that comes with VS. It then creates the serialized classes based on your schemas. You can then use them in your method as input variables and return values.

Here is the article:
http://msdn.microsoft.com/architectu...soiwithnet.asp
"Dan Marshall" wrote:
The class doesn't seem to return readonly properties...Is anybody able to do this?
Dan

"Manohar Kamath" wrote:
Stan,

I don't think there is any whitepaper on the above. The classes you use in WebServices are nothing but state objects -- with Get/Set properties. Hence, they can be represented as XML (for the structured data). Passing objects instead of XMl makes it easier to play with the data on the either side -- else you will have to use XML parsers to get values; I would almost always prefer a class.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Stan" <no****@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...
> There are two ways to pass structured data to a web service:
>
> xml
> ===
>
> <Order OrderId="123" OrderAmount="234" />
>
> or class
> =====
>
> public class Order
> {
> public string OrderId;
> public deciaml OrderAmount;
> }
>
> Class will be serialized to xml and on soap level there will be no
> difference.
>
> Are there any white paper or any guideline document which compares these two
> methods? In which cases should I use one or another?
>
> For example, test page is not available when passing a class, but xml is > used, I can make it Notepad and paste it into the test page.
>
>
> Thanks,
>
> -Stan
>
>

Nov 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Read | last post by:
Dear all, I thought I understood passing parameters ByVal and ByRef but I clearly don't! If I define a simple class of: Public Class Person Public Name as String Public Age as Integer End...
15
by: Dave | last post by:
I'm currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I'm passing an array of 50000 int's. ...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
3
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes...
2
by: Witold Iwaniec via .NET 247 | last post by:
It seems that when you pass an object to a function it is always passed by reference even if it is explicitly declared ByVal. Is it the behavior of VB.Net? Here is sample code from sample Asp.Net...
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.