473,725 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serailize RCW class OR IPersistStream call to RCW class question

Hi.

I have a RCW class that was generated by the VS.NET2003 IDE when I added a
COM dll reference to my project. This all works fine when I call methods on
it. My initial problem is that in ASP.NET I would like to add this to the
Session object whilst using SQLServer as the session storage. Unfortunately,
as this required the RCW class to be serializable, this won't work, and
throws an exception saying you can't Serialize the Session state if it
contains objects that are MarshalByRef and the session state mode is
SQLServer.

So question 1 - Is there an easy way to make an RCW class serializable? (I'm
expecting this to be "No", but if you don't ask you don't get)

Question 2 - My COM dll is capable of storing its own state, via its
implementation of IPersistStream. After a lot of Googling I've added C#
definitions of IPersist and IPersistStream. If I have a class AAA which
contains an instance of MyLib::IRCWClas s which is marked as
NonSerializable , then I've set AAA to implement ISerializable, and in
GetObjectData() I have

MemoryStream memstream = new MemoryStream();
ComStream cstream = new ComStream(memst ream);
IPersistStream pStream = (IPersistStream )m_RCWClass;

if ( pStream != null )
pStream.Save( cstream, false );
else
Trace.WriteLine ( "No IPersistStream" );

This throws the same exception when it calls Save. However if I change the
third line to

IPersistStream pStream = m_RCWClass as IPersistStream;

This also throws the same exception. Is there any way to gain access to the
IPersistStream methods, and then serialize the contents of my stream?

Question 3 - As an alternative approach, I've tried to get the bytes out of
the IPersistStream another way, with a view to storing this byte array
separately in the Session object. A first attempt is

IPersistStream p = m_AAAClass.RCWC lass as IPersistStream;

if ( p != null )
{
System.IO.Memor yStream memstream = new System.IO.Memor yStream();
ComStream cstream = new ComStream(memst ream);
if ( p != null )
{
p.Save( cstream, false );
System.IO.Memor yStream mem = cstream.stream as
System.IO.Memor yStream;
return mem.GetBuffer() ;
}
else
return null;
}
return null;

This time the pointer to IPersistStream is null the first time, but after
that always throws a COMException with the message "The server threw an
exception". Am I barking up the wrong tree?

Fundamentally wanting to store an RCW class in the Session object doesn't
seem to be a strange thing to want to do, but after Googling myself into a
frenzy, it seems that very few people have asked about it. Those that have
have been told to set the sesseion state to InProc, but this isn't really an
option, as this means you can't run on a web farm. Any ideas please?

Cheers,

Chris

Nov 19 '05 #1
2 1604
Well, when you think of what RCW stands for, its simply a wrapper for
another class. In this case, its a wrapper to a com instance which may or
may not me serializable (remember that could be looking at a c++ 6.0 on the
other side of a wrapper.

Secondly, the COM+ paradigm focuses on a service oriented architecture
where your COM+ components are stateless, or maintain a transient state. So
if you have a COM+ class that does need to maintain sone sort of state, then
your might need to re-architect your solution.

Now, there is no reason that a serializable class can not call a COM+
instance to perform some kind of action. That might be something that can
help you out. Also you can pass serializable classes to COM+ components by
reference.

You'll really want to take a lok at your state management strategy as a
whole and see if there os some way of bringing it down to a single point.
In the traditional approach to web applications, this has meant that state
was always managed through the use of relational databases (e.g. the famous
Shopping cart). I'm not recommenting this as a target architecture, but it
you can take a look at your user state from the standpoint of creating a
single "thing" database, class, session object, etc, that represents your
state, it might clear things up

"Chris Puncher" <ch************ *******@NOdocum ationSPAM.co.uk > wrote in
message news:eA******** ******@TK2MSFTN GP11.phx.gbl...
Hi.

I have a RCW class that was generated by the VS.NET2003 IDE when I added a
COM dll reference to my project. This all works fine when I call methods on it. My initial problem is that in ASP.NET I would like to add this to the
Session object whilst using SQLServer as the session storage. Unfortunately, as this required the RCW class to be serializable, this won't work, and
throws an exception saying you can't Serialize the Session state if it
contains objects that are MarshalByRef and the session state mode is
SQLServer.

So question 1 - Is there an easy way to make an RCW class serializable? (I'm expecting this to be "No", but if you don't ask you don't get)

Question 2 - My COM dll is capable of storing its own state, via its
implementation of IPersistStream. After a lot of Googling I've added C#
definitions of IPersist and IPersistStream. If I have a class AAA which
contains an instance of MyLib::IRCWClas s which is marked as
NonSerializable , then I've set AAA to implement ISerializable, and in
GetObjectData() I have

MemoryStream memstream = new MemoryStream();
ComStream cstream = new ComStream(memst ream);
IPersistStream pStream = (IPersistStream )m_RCWClass;

if ( pStream != null )
pStream.Save( cstream, false );
else
Trace.WriteLine ( "No IPersistStream" );

This throws the same exception when it calls Save. However if I change the
third line to

IPersistStream pStream = m_RCWClass as IPersistStream;

This also throws the same exception. Is there any way to gain access to the IPersistStream methods, and then serialize the contents of my stream?

Question 3 - As an alternative approach, I've tried to get the bytes out of the IPersistStream another way, with a view to storing this byte array
separately in the Session object. A first attempt is

IPersistStream p = m_AAAClass.RCWC lass as IPersistStream;

if ( p != null )
{
System.IO.Memor yStream memstream = new System.IO.Memor yStream();
ComStream cstream = new ComStream(memst ream);
if ( p != null )
{
p.Save( cstream, false );
System.IO.Memor yStream mem = cstream.stream as
System.IO.Memor yStream;
return mem.GetBuffer() ;
}
else
return null;
}
return null;

This time the pointer to IPersistStream is null the first time, but after
that always throws a COMException with the message "The server threw an
exception". Am I barking up the wrong tree?

Fundamentally wanting to store an RCW class in the Session object doesn't
seem to be a strange thing to want to do, but after Googling myself into a
frenzy, it seems that very few people have asked about it. Those that have
have been told to set the sesseion state to InProc, but this isn't really an option, as this means you can't run on a web farm. Any ideas please?

Cheers,

Chris

Nov 19 '05 #2
David,

Thanks for your reply. The posistion I'm in is that the company I work for
has a successful web product (ASP/C++ ATL COM). This is gradually being
moved to ASP.NET, but in the process many of the underlying COM components
will still be used, albeit with thin C# .NET wrappers on top. The COM
component that I'm having problems with is our existing session state
object, hence its ability to stream itself (where in the old product it is
written to a SQLServer database). This object is then deserialised and
passed into many of the other COM components which are required to perform
business functionality.

So what I am trying to do is put the RCW class instance for the existing
session state object into ASP.NET's Session object, and hence to SQLServer.
Failing this then if I can get at the byte stream that represents the old
session state object, I'll be happy to stick that in Session.

I hope this clears up my question a bit.

Cheers,

Chris

"David Jessee" <dj*****@housto n.rr.com> wrote in message
news:us******** ******@TK2MSFTN GP11.phx.gbl...
Well, when you think of what RCW stands for, its simply a wrapper for
another class. In this case, its a wrapper to a com instance which may or
may not me serializable (remember that could be looking at a c++ 6.0 on the other side of a wrapper.

Secondly, the COM+ paradigm focuses on a service oriented architecture
where your COM+ components are stateless, or maintain a transient state. So if you have a COM+ class that does need to maintain sone sort of state, then your might need to re-architect your solution.

Now, there is no reason that a serializable class can not call a COM+
instance to perform some kind of action. That might be something that can
help you out. Also you can pass serializable classes to COM+ components by reference.

You'll really want to take a lok at your state management strategy as a
whole and see if there os some way of bringing it down to a single point.
In the traditional approach to web applications, this has meant that state
was always managed through the use of relational databases (e.g. the famous Shopping cart). I'm not recommenting this as a target architecture, but it
you can take a look at your user state from the standpoint of creating a
single "thing" database, class, session object, etc, that represents your
state, it might clear things up

"Chris Puncher" <ch************ *******@NOdocum ationSPAM.co.uk > wrote in
message news:eA******** ******@TK2MSFTN GP11.phx.gbl...
Hi.

I have a RCW class that was generated by the VS.NET2003 IDE when I added a COM dll reference to my project. This all works fine when I call methods on
it. My initial problem is that in ASP.NET I would like to add this to the Session object whilst using SQLServer as the session storage.

Unfortunately,
as this required the RCW class to be serializable, this won't work, and
throws an exception saying you can't Serialize the Session state if it
contains objects that are MarshalByRef and the session state mode is
SQLServer.

So question 1 - Is there an easy way to make an RCW class serializable?

(I'm
expecting this to be "No", but if you don't ask you don't get)

Question 2 - My COM dll is capable of storing its own state, via its
implementation of IPersistStream. After a lot of Googling I've added C#
definitions of IPersist and IPersistStream. If I have a class AAA which
contains an instance of MyLib::IRCWClas s which is marked as
NonSerializable , then I've set AAA to implement ISerializable, and in
GetObjectData() I have

MemoryStream memstream = new MemoryStream();
ComStream cstream = new ComStream(memst ream);
IPersistStream pStream = (IPersistStream )m_RCWClass;

if ( pStream != null )
pStream.Save( cstream, false );
else
Trace.WriteLine ( "No IPersistStream" );

This throws the same exception when it calls Save. However if I change the third line to

IPersistStream pStream = m_RCWClass as IPersistStream;

This also throws the same exception. Is there any way to gain access to

the
IPersistStream methods, and then serialize the contents of my stream?

Question 3 - As an alternative approach, I've tried to get the bytes out

of
the IPersistStream another way, with a view to storing this byte array
separately in the Session object. A first attempt is

IPersistStream p = m_AAAClass.RCWC lass as IPersistStream;

if ( p != null )
{
System.IO.Memor yStream memstream = new System.IO.Memor yStream();
ComStream cstream = new ComStream(memst ream);
if ( p != null )
{
p.Save( cstream, false );
System.IO.Memor yStream mem = cstream.stream as
System.IO.Memor yStream;
return mem.GetBuffer() ;
}
else
return null;
}
return null;

This time the pointer to IPersistStream is null the first time, but after that always throws a COMException with the message "The server threw an
exception". Am I barking up the wrong tree?

Fundamentally wanting to store an RCW class in the Session object doesn't seem to be a strange thing to want to do, but after Googling myself into a frenzy, it seems that very few people have asked about it. Those that have have been told to set the sesseion state to InProc, but this isn't

really an
option, as this means you can't run on a web farm. Any ideas please?

Cheers,

Chris


Nov 19 '05 #3

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

Similar topics

3
331
by: Angus Comber | last post by:
Hello I am attempting to build a set of classes which handle telephony. Basically the handling of phone calls. My design currently has two main classes - one dealing with the device and the other with actual calls. So you could say I have a device class and a calls class. The device here is a telephone handset basically. Telephones connected to business switchboards can hanlde more than one call at a time - eg you can have one...
13
2730
by: jt | last post by:
Being a newbie in C++ and comming from C, I can't find information on how to access a class member function outside its class. Below is a snippet of the class and its member function: look at "AddCallPages" ============================================================= class CPsnstatuspttView : public CFormView { protected: // create from serialization only CPsnstatuspttView();
2
4221
by: Andrea Gavana | last post by:
Hello NG, this may seem a stupid (or even impossible) question, but my knowlegde of Python is quite limited. I have basically a simple graphical user interface that contains a Panel, another panel (child of the main panel) and a custom widget (child of the main panel). Basically is something like (only some small code, is in wxPython but the question is more Python-related): class MainClass(wx.Panel):
1
2547
by: J Askey | last post by:
Is this object available in Access? If so, what do I need to set a reference to? My bigger picture is needing a way to take a .bmp out of a SQL database and put into both an CommandBarButton image and an Access.Image. I have found lots of peices to get the .bmp into a byte array, then the byte array into a StdPicture and then a StdPicture into an iPicture but Im needing the IPersistStream object to do this. Any other suggestions welcome...
3
3345
by: Robin Tucker | last post by:
Does anyone have a VB.NET IPersistStream COM interface description I can cadge please? If I remember rightly, you have to "flatten" inherited COM interfaces (I think IPersistStream derives from IPersist or something). Thanks, Robin
4
3143
by: Charles Churchill | last post by:
I apologize if this question has been asked before, but after about half an hour of searching I haven't been able to find an answer online. My code is beloiw, with comments pertaining to my question In short my question is why when I pass a generic type directly to the formatObject function it works fine, but when I pass it to the checkText function where it is itself a generic argument, and then it is passed to formatObject, it is seen...
9
5849
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to the static Parse method of the conversion class. if (InValue is string) return T.Parse((string)InValue); else return base.ConvertFrom(context, culture, InValue);
5
1781
by: Brad Pears | last post by:
Hi guys!!! Thanks for all your input on previous OO posts. I know it will be all the same people responding again and I really appreciate your insight etc.. as you all appear to know what you are doing - each having your own flare but that is what makes us individuals right?? Anyway, here is a quick question... (or maybe not so quick) In my business "Contract" class I have many properties. When I set these "contract" properties in the...
1
1363
by: =?Utf-8?B?dG9iaXdhbl9rZW5vYmk=?= | last post by:
In the following code, calling CallTestMethod() from an instance of the derived class (the base is abstract and we can never instantiate it), referencing 'base.TestMethod()' actually calls 'TestMethod()' in the base class, but referencing 'this.CallTestMethod()' (defined in the base class) references the overriding method, not the method defined within the base class, making calling 'TestMethod()' seem virtually impossible (pun intended). ...
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.