473,326 Members | 2,081 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,326 software developers and data experts.

Passing Complex objects to MSMQ

Hello,
I am building a system in C# 2.0 using the master - worker design
pattern
The system is supposed to work as follows:
1. The Master sends Command objects to several workers
2. All Commands are derived from AbstractCommand class (but are
significantly different from each other)

Since the system is distributed and should be presistant, I want to use

MSMQ to pass the Command object to the Workers
The object which I send to the MSMQ is a message containing an object
of type Abstract Command.
The problem is that MSMQ needs the objects passed into the queue to be
serializable.
In order to maintain abstraction and reusability, I want to send the
AbsCommand in the message rather then a specific type of command. when
I try to do this, the MSMQ throws exceptions because of the
serialization of the abstract command contained in the message.
Is there anyway to get around this and to send an object to the msmq
which contains an interface or an abstract object?
Thanks,
Yoni Rabin
//In this illustration, I need to send the message object to the MSMQ
and later read it
// on the other side
[Serializable]
public class message
{
public abstract AbstractCommand;

}
[Serializable]
public abstract class AbstractCommand
{
}
[Serializable]
public class MyCommand:AbstractCommand
{
public string property;

Aug 22 '06 #1
3 6350
<yo*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I try to do this, the MSMQ throws exceptions because of the
serialization of the abstract command contained in the message.
What is the error message that you are getting?

-- Alan
Aug 22 '06 #2

In 1.1, I am going this. I have an interface, and just before I send it to
the queue as a message ( and the message.Body ), I cast it as the
IInterface.

IAnimal
void Go();

Dog : IAnimal
Cat : IAnimal
I'd check out http://www.eggheadcafe.com/articles/20041204.asp
where Peter does a great job of bringing the Command Pattern and the MSMQ
together.

My send method looks like this

SendAMessage (IAnimal anm )
{

}

and right before I call the method I go a:

Dog d = new Dog();

this.SendAMessage ( (IAnimal) d );
Anyway... maybe that's not the issue in 2.0, but I'd thought I'd share what
I knew.


<yo*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hello,
I am building a system in C# 2.0 using the master - worker design
pattern
The system is supposed to work as follows:
1. The Master sends Command objects to several workers
2. All Commands are derived from AbstractCommand class (but are
significantly different from each other)

Since the system is distributed and should be presistant, I want to use

MSMQ to pass the Command object to the Workers
The object which I send to the MSMQ is a message containing an object
of type Abstract Command.
The problem is that MSMQ needs the objects passed into the queue to be
serializable.
In order to maintain abstraction and reusability, I want to send the
AbsCommand in the message rather then a specific type of command. when
I try to do this, the MSMQ throws exceptions because of the
serialization of the abstract command contained in the message.
Is there anyway to get around this and to send an object to the msmq
which contains an interface or an abstract object?
Thanks,
Yoni Rabin
//In this illustration, I need to send the message object to the MSMQ
and later read it
// on the other side
[Serializable]
public class message
{
public abstract AbstractCommand;

}
[Serializable]
public abstract class AbstractCommand
{
}
[Serializable]
public class MyCommand:AbstractCommand
{
public string property;

Aug 22 '06 #3

PS

IAnimal has to be serializable.

"sloan" <sl***@ipass.netwrote in message
news:ek**************@TK2MSFTNGP04.phx.gbl...
>
In 1.1, I am going this. I have an interface, and just before I send it to
the queue as a message ( and the message.Body ), I cast it as the
IInterface.

IAnimal
void Go();

Dog : IAnimal
Cat : IAnimal
I'd check out http://www.eggheadcafe.com/articles/20041204.asp
where Peter does a great job of bringing the Command Pattern and the MSMQ
together.

My send method looks like this

SendAMessage (IAnimal anm )
{

}

and right before I call the method I go a:

Dog d = new Dog();

this.SendAMessage ( (IAnimal) d );
Anyway... maybe that's not the issue in 2.0, but I'd thought I'd share
what
I knew.


<yo*******@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hello,
I am building a system in C# 2.0 using the master - worker design
pattern
The system is supposed to work as follows:
1. The Master sends Command objects to several workers
2. All Commands are derived from AbstractCommand class (but are
significantly different from each other)

Since the system is distributed and should be presistant, I want to use

MSMQ to pass the Command object to the Workers
The object which I send to the MSMQ is a message containing an object
of type Abstract Command.
The problem is that MSMQ needs the objects passed into the queue to be
serializable.
In order to maintain abstraction and reusability, I want to send the
AbsCommand in the message rather then a specific type of command. when
I try to do this, the MSMQ throws exceptions because of the
serialization of the abstract command contained in the message.
Is there anyway to get around this and to send an object to the msmq
which contains an interface or an abstract object?
Thanks,
Yoni Rabin
//In this illustration, I need to send the message object to the MSMQ
and later read it
// on the other side
[Serializable]
public class message
{
public abstract AbstractCommand;

}
[Serializable]
public abstract class AbstractCommand
{
}
[Serializable]
public class MyCommand:AbstractCommand
{
public string property;


Aug 22 '06 #4

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

Similar topics

2
by: Martin. D. Waller | last post by:
Hello, Does anyone kow of any good examples or documents that talk about serializing complex objects and object graphs to XML. Basically I would like to have a class that references other...
0
by: AliceSee | last post by:
I have two Application Domain A and B. I declare an MarshalByRef object called ObjectA in Domain A. I declare another MarshalByRef object called ObjectB in Domain B. ObjectB has a function...
25
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business...
5
by: Trail Monster | last post by:
Ok, I've been searching the net now for several days and can't find how to do this anywhere. Version: VS 2005 Professional Release, 2.0 Framework Background: I have a complex business object...
2
by: PeteZ | last post by:
Can someone help me here. I'm having trouble finding details on how complex objects (eg. an object created in a code behind page that has imbedded object references, collections etc imbedded in...
7
by: silversurfer2025 | last post by:
Hello, I would like to overload the operators *, + and = in a class, which is used much like a vector (such as in linear algebra). For this, I need to be able to add featureVectors to each other,...
1
by: m.i.mustafa | last post by:
I'm having problems with De-Serializing a complex object I'm sending through a queue. I call it a complex object simply because its a business object that is composed of other objects. Now all...
3
by: andreas.baus | last post by:
Hello. I'm trying to exchange data between a webservice based on Apache Axis and a client written in C#, and so far it has been working with few problems (none that I couldn't solve myself with...
7
by: =?iso-8859-1?Q?S=F8ren_M._Olesen?= | last post by:
Hi How do I pass a complex type to a webservice?? What I have is a Class 'MyComplexClass' which lives in it's own dll/namespace. I'd like to pass this class to my webmethod: <WebMethod()_...
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
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.