Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Serailize RCW class OR IPersistStream call to RCW class question

Reply
Thread Tools

Serailize RCW class OR IPersistStream call to RCW class question

 
 
Chris Puncher
Guest
Posts: n/a
 
      01-19-2005
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::IRCWClass 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(memstream);


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.RCWClass as IPersistStream;

if ( p != null )
{
System.IO.MemoryStream memstream = new System.IO.MemoryStream();
ComStream cstream = new ComStream(memstream);
if ( p != null )
{
p.Save( cstream, false );
System.IO.MemoryStream mem = cstream.stream as
System.IO.MemoryStream;
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



 
Reply With Quote
 
 
 
 
David Jessee
Guest
Posts: n/a
 
      01-20-2005
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" <> wrote in
message news:eAXk1pk$...
> 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::IRCWClass 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(memstream);
>
>
> 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.RCWClass as IPersistStream;
>
> if ( p != null )
> {
> System.IO.MemoryStream memstream = new System.IO.MemoryStream();
> ComStream cstream = new ComStream(memstream);
> if ( p != null )
> {
> p.Save( cstream, false );
> System.IO.MemoryStream mem = cstream.stream as
> System.IO.MemoryStream;
> 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
>
>
>



 
Reply With Quote
 
 
 
 
Chris Puncher
Guest
Posts: n/a
 
      01-20-2005
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" <> wrote in message
news:usp0VGs$...
> 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" <> wrote in
> message news:eAXk1pk$...
> > 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::IRCWClass 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(memstream);
> >
> >
> > 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.RCWClass as IPersistStream;
> >
> > if ( p != null )
> > {
> > System.IO.MemoryStream memstream = new System.IO.MemoryStream();
> > ComStream cstream = new ComStream(memstream);
> > if ( p != null )
> > {
> > p.Save( cstream, false );
> > System.IO.MemoryStream mem = cstream.stream as
> > System.IO.MemoryStream;
> > 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
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class Function call vs Normal Function call THAKUR PRASHANT SINGH Ruby 7 02-27-2010 07:04 AM
SKYPE + VoSKY Call Centre - Call Forwarding Question. Mark UK VOIP 4 08-04-2006 10:15 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
COM object separated from its underlying RCW error =?Utf-8?B?R3JhbnQ=?= ASP .Net 0 06-30-2005 12:33 PM
COM object that has been separated from its underlying RCW can not be used. Rahul T. ASP .Net 3 12-03-2004 12:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57