473,320 Members | 1,987 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,320 software developers and data experts.

Wrap a Serializable Object

I'm wanting to create a Wrapper (or Extender depending on how you look at
it) for a Serializable object that I then want to send over a webservice.
Basically I want to create a Serializable Object, which has some properties
on it, but I want to make one of the Properties a generic type that I can
assign one of multiple Serializable object. I've look at creating it using
an XmlNode and an object but so far both appear to have issues. I've looked
at a few things, but they appear to have issues. Does anyone have
suggestions?

In the event I haven't explained this well enough, I have some code.... My
Wrapper Class is what I want to pass back and forth across the WebService.
I want the Wrapper Class's WrappableObject property to hold and instance of
ObjectA, ObjectB, etc.... (i.e. anything that is Serialiable)

[Serializable()]
public class Wrapper
{
private string msName;
private XmlNode mxnWrappableObject;

public string Name
{
get {return msName;}
set {msName = value:}
}

public XmlNode WrappableObject
{
get {return mxnWrappableObject;}
set {mxnWrappableObject = value;}
}
}

[Serializable()]
public class ObjectA
{
private string msFirstName;
private string msLastName;

public string FirstName
{
get {return msFirstName;}
set {msFirstName= value:}
}

public string LastName
{
get {return msLastName;}
set {msLastName= value;}
}
}
[Serializable()]
public class ObjectB
{
private string msAccount;
private string msBalance;

public string Account
{
get {return msAccount;}
set {msAccount= value:}
}

public string Balance
{
get {return msBalance;}
set {msBalance= value;}
}
}
Aug 10 '06 #1
3 1781
Hiya,

does the following code snippet help you? It's in VB.NET, but should be
pretty easy to convert to C#.NET

<System.Xml.Serialization.XmlElementAttribute("Obj ectA", GetType(ObjectA)),
_

System.Xml.Serialization.XmlElementAttribute("Obje ctB", GetType(ObjectB))_

Public Item As Object

This essentially says that the Item can be of type ObjectA or ObjectB and
tells the object how to serialize in each case.

Andrew

"Techno_Dex" <no**********@osi-corp.comwrote in message
news:u4*************@TK2MSFTNGP05.phx.gbl...
I'm wanting to create a Wrapper (or Extender depending on how you look at
it) for a Serializable object that I then want to send over a webservice.
Basically I want to create a Serializable Object, which has some
properties on it, but I want to make one of the Properties a generic type
that I can assign one of multiple Serializable object. I've look at
creating it using an XmlNode and an object but so far both appear to have
issues. I've looked at a few things, but they appear to have issues.
Does anyone have suggestions?

In the event I haven't explained this well enough, I have some code.... My
Wrapper Class is what I want to pass back and forth across the WebService.
I want the Wrapper Class's WrappableObject property to hold and instance
of ObjectA, ObjectB, etc.... (i.e. anything that is Serialiable)

[Serializable()]
public class Wrapper
{
private string msName;
private XmlNode mxnWrappableObject;

public string Name
{
get {return msName;}
set {msName = value:}
}

public XmlNode WrappableObject
{
get {return mxnWrappableObject;}
set {mxnWrappableObject = value;}
}
}

[Serializable()]
public class ObjectA
{
private string msFirstName;
private string msLastName;

public string FirstName
{
get {return msFirstName;}
set {msFirstName= value:}
}

public string LastName
{
get {return msLastName;}
set {msLastName= value;}
}
}
[Serializable()]
public class ObjectB
{
private string msAccount;
private string msBalance;

public string Account
{
get {return msAccount;}
set {msAccount= value:}
}

public string Balance
{
get {return msBalance;}
set {msBalance= value;}
}
}

Aug 14 '06 #2
I don't think will work for what I'm looking to do (I'm not sure I
completely follow your example). The XmlElementAttribute is a single string
attribute assigned to an Element. If I have an object which has a hierarchy
structure (similar to a DataSet, i.e. anything with a collection of items),
I take it you are trying to serialize it as a flat string on a generic
element and pass this back and forth. This starts to get into having to
escape values in the hierarchy like the angle brackets in order to pass it
as a string across the web service. I think the XmlNode is the route I need
to go, but I don't think it's going to be as nice as I would like to be.
"Andrew Brook" <yk****@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hiya,

does the following code snippet help you? It's in VB.NET, but should be
pretty easy to convert to C#.NET

<System.Xml.Serialization.XmlElementAttribute("Obj ectA",
GetType(ObjectA)), _

System.Xml.Serialization.XmlElementAttribute("Obje ctB", GetType(ObjectB))>
_

Public Item As Object

This essentially says that the Item can be of type ObjectA or ObjectB and
tells the object how to serialize in each case.

Andrew

"Techno_Dex" <no**********@osi-corp.comwrote in message
news:u4*************@TK2MSFTNGP05.phx.gbl...
>I'm wanting to create a Wrapper (or Extender depending on how you look at
it) for a Serializable object that I then want to send over a webservice.
Basically I want to create a Serializable Object, which has some
properties on it, but I want to make one of the Properties a generic type
that I can assign one of multiple Serializable object. I've look at
creating it using an XmlNode and an object but so far both appear to have
issues. I've looked at a few things, but they appear to have issues.
Does anyone have suggestions?

In the event I haven't explained this well enough, I have some code....
My Wrapper Class is what I want to pass back and forth across the
WebService. I want the Wrapper Class's WrappableObject property to hold
and instance of ObjectA, ObjectB, etc.... (i.e. anything that is
Serialiable)

[Serializable()]
public class Wrapper
{
private string msName;
private XmlNode mxnWrappableObject;

public string Name
{
get {return msName;}
set {msName = value:}
}

public XmlNode WrappableObject
{
get {return mxnWrappableObject;}
set {mxnWrappableObject = value;}
}
}

[Serializable()]
public class ObjectA
{
private string msFirstName;
private string msLastName;

public string FirstName
{
get {return msFirstName;}
set {msFirstName= value:}
}

public string LastName
{
get {return msLastName;}
set {msLastName= value;}
}
}
[Serializable()]
public class ObjectB
{
private string msAccount;
private string msBalance;

public string Account
{
get {return msAccount;}
set {msAccount= value:}
}

public string Balance
{
get {return msBalance;}
set {msBalance= value;}
}
}


Aug 14 '06 #3
Hiya,

I didn't mean that the code would flatten any collection into a generic
string. Just that you can say that an object serializes in two different
ways depending on the type of the object assigned to it. In my example, the
"Item" element would serialize to be either ObjectA or ObjectB, where these
objects can be (serializable) complex class structures.
I suppose it's more of a problem if there is no limit to the types of class
that you want to "wrap".

Andrew

"Techno_Dex" <no**********@osi-corp.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>I don't think will work for what I'm looking to do (I'm not sure I
completely follow your example). The XmlElementAttribute is a single
string attribute assigned to an Element. If I have an object which has a
hierarchy structure (similar to a DataSet, i.e. anything with a collection
of items), I take it you are trying to serialize it as a flat string on a
generic element and pass this back and forth. This starts to get into
having to escape values in the hierarchy like the angle brackets in order
to pass it as a string across the web service. I think the XmlNode is the
route I need to go, but I don't think it's going to be as nice as I would
like to be.
"Andrew Brook" <yk****@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>Hiya,

does the following code snippet help you? It's in VB.NET, but should be
pretty easy to convert to C#.NET

<System.Xml.Serialization.XmlElementAttribute("Ob jectA",
GetType(ObjectA)), _

System.Xml.Serialization.XmlElementAttribute("Obj ectB",
GetType(ObjectB))_

Public Item As Object

This essentially says that the Item can be of type ObjectA or ObjectB and
tells the object how to serialize in each case.

Andrew

"Techno_Dex" <no**********@osi-corp.comwrote in message
news:u4*************@TK2MSFTNGP05.phx.gbl...
>>I'm wanting to create a Wrapper (or Extender depending on how you look
at it) for a Serializable object that I then want to send over a
webservice. Basically I want to create a Serializable Object, which has
some properties on it, but I want to make one of the Properties a
generic type that I can assign one of multiple Serializable object.
I've look at creating it using an XmlNode and an object but so far both
appear to have issues. I've looked at a few things, but they appear to
have issues. Does anyone have suggestions?

In the event I haven't explained this well enough, I have some code....
My Wrapper Class is what I want to pass back and forth across the
WebService. I want the Wrapper Class's WrappableObject property to hold
and instance of ObjectA, ObjectB, etc.... (i.e. anything that is
Serialiable)

[Serializable()]
public class Wrapper
{
private string msName;
private XmlNode mxnWrappableObject;

public string Name
{
get {return msName;}
set {msName = value:}
}

public XmlNode WrappableObject
{
get {return mxnWrappableObject;}
set {mxnWrappableObject = value;}
}
}

[Serializable()]
public class ObjectA
{
private string msFirstName;
private string msLastName;

public string FirstName
{
get {return msFirstName;}
set {msFirstName= value:}
}

public string LastName
{
get {return msLastName;}
set {msLastName= value;}
}
}
[Serializable()]
public class ObjectB
{
private string msAccount;
private string msBalance;

public string Account
{
get {return msAccount;}
set {msAccount= value:}
}

public string Balance
{
get {return msBalance;}
set {msBalance= value;}
}
}



Aug 15 '06 #4

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

Similar topics

0
by: xmail123 | last post by:
Hi, Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web...
8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
3
by: Alexander Wehrli | last post by:
Hi guys What I am doing: I'm saving some configuration stuff in an Class called Options. This class has got some String, bool and an int Member. I Serialize (binary) this object in a file. ...
3
by: Raghavendra Tilve | last post by:
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Description: An...
1
by: Harshdeep Mehta | last post by:
Hi all, I have written a page in which I want to preserve value of object - suppose A - value, so I used viewstate. but that give me error. Code : ViewState = objClassA; // Before PostBack...
8
by: Techno_Dex | last post by:
Has anyone come up with a slick way to make Custom Serializable Objects to behave like DataSets when using WebServices? What I'm looking for is some way to force the WSDL generated code to create...
0
mmfranke
by: mmfranke | last post by:
Hello. Hi. I'm writing a logging service that uses .NET remoting. The idea is that the service publishes an EventProcessor object that clients can access via .NET Remoting, passing it...
4
by: owen79 | last post by:
Hi, Disappointingly, I think I already know the answer to this question. I have a C# class which I'm effectively using as a storage area while I carry out a sequence of Web Method calls on a...
2
by: Morten Snedker | last post by:
<Serializable()Public Class Dealer What does Serializable do? Regards /Snedker
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.