Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2007

Tip: Looking for answers? Try searching our database.

Using COM objects in ASP.NET and postback problems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alain Sienaert - 26 Jan 2007 00:00 GMT
Hi,

I'm currently investigating the possibility of upgrading an existing website
(ISAPI written in Delphi) to an ASP.NET 2.0 application (Visual Studio
2005 - C#).

The website itself communicates with an executable (ColPro.exe) that support
COM+.
The idea is that for every user (ASP.NET session) the ColPro.exe should be
launched, that the user can set individual properties and make some
calculations using one or more ASPX pages.
The ColPro.exe application should be closed when the ASP.NET session is
closed.

I managed to implement the basic idea using early and late binding (see code
below).
However, this code only works as long as you do not fire a postback. As soon
as a postback is fired (e.g. by pressing a button) the reference to the COM
object is lost.

Any idea on how we can store the reference to our COM object?

All help is really appreciated,
Alain

   protected void Button2_Click(object sender, EventArgs e)
   {
       t = Type.GetTypeFromProgID("ColPro.App");
       o = Activator.CreateInstance(t);

       object invokeResult;

       invokeResult = t.InvokeMember("SetDataSet",
BindingFlags.InvokeMethod, null, o, new Object[] {"ABS"});

       invokeResult = t.InvokeMember("SetRegion",
BindingFlags.InvokeMethod, null, o, new Object[] {"PPC"});

       invokeResult = t.InvokeMember("Open",  BindingFlags.InvokeMethod,
null, o, null);

       invokeResult = t.InvokeMember("SetPigColor",
BindingFlags.InvokeMethod, null, o, new Object[] {1,"P.Yellow 183"});

       invokeResult = t.InvokeMember("Quit", BindingFlags.InvokeMethod,
null, o, null);

       Marshal.ReleaseComObject(o);
   }

   protected void Button3_Click(object sender, EventArgs e)
   {
       cp = new ColPro.App();
       Session.Add("MyCP", cp);

       string str = "ABS";
       Object o = str;
       cp.SetDataSet(ref o);

       str = "PPC";
       Object p = str;
       cp.SetRegion(ref p);

       cp.Open();

       p = "P.Yellow 183";
       cp.SetPigColor(3, ref p);

       double d = 0.123;
       Object q = d;
       cp.SetPigValue(3, ref q);

       cp.Quit();

       Marshal.ReleaseComObject(cp);
   }
L-E Eriksson - 26 Jan 2007 13:17 GMT
Hello!

I guess you could use the session object to keep a reference to the instance
of the com-object. But why start a separate instance of colpro.exe for every
user? This will become cumbersome for your server quickly.

Note: I know nothing about colpro.exe

Regards

L-E Eriksson

> Hi,
>
[quoted text clipped - 77 lines]
>        Marshal.ReleaseComObject(cp);
>    }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.