Connecting Tech Pros Worldwide Forums | Help | Site Map

Using an ActiveX in a Web service

Oriane
Guest
 
Posts: n/a
#1: Jul 24 '08
Hi there,

I need to use an ActiveX inside a Web service. My problem is that I need an
handle on this Com component, so I add a reference to my .Net project, and I
create an instance of class of this Com exe. But I then realize that each
time I call for a method of my web service, I create a new Com exe process,
which is not what I want.

Any idea to avoid this pitfall ?

Philippe


Munna
Guest
 
Posts: n/a
#2: Jul 24 '08

re: Using an ActiveX in a Web service


HI,

I don't know much of com... but still want to share the thought
can't you load the componet in application start in global.ascx
and the share the same component in all the request...

regards

Munna
Steven Cheng [MSFT]
Guest
 
Posts: n/a
#3: Jul 25 '08

re: Using an ActiveX in a Web service


Hi Philippe ,

For your scenario, since you're calling an out-of-process COM object, it
will launch new COM process for new created object. To avoid this, I agree
with Munna that you can use a global variable(such as a static class
member) to cache a single instance of the COM component instance(something
like a singleton wrapper class) and all your webservice methods will use
that one. There is several things you need to take care here:

1. The COM component might not be thread safe, so for such multi-threading
environment, you will need to lock it when accessing it in each thread.

2. If #1 will make your performance impacted, consider creating multiple
such global instances as a pool so that you can always reuse these pooled
instances.

3. for .NET webservice/web application environment, the thread is MTA
thread while most COM objects are STA, this will make an additional calling
gap between them. If the COM is really an STA one, you may need to adjust
your webservice thread's COM apartment model, see the following article:

#Running ASMX Web Services on STA Threads
http://msdn.microsoft.com/en-us/magazine/cc163544.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Quote:
>From: "Oriane" <oriane@noemail.noemail>
>Subject: Using an ActiveX in a Web service
>Date: Thu, 24 Jul 2008 18:26:08 +0200
Quote:
>
>Hi there,
>
>I need to use an ActiveX inside a Web service. My problem is that I need
an
Quote:
>handle on this Com component, so I add a reference to my .Net project, and
I
Quote:
>create an instance of class of this Com exe. But I then realize that each
>time I call for a method of my web service, I create a new Com exe
process,
Quote:
>which is not what I want.
>
>Any idea to avoid this pitfall ?
>
>Philippe
>
>
Oriane
Guest
 
Posts: n/a
#4: Jul 28 '08

re: Using an ActiveX in a Web service


Hi Steven,
"Steven Cheng [MSFT]" <stcheng@online.microsoft.coma écrit dans le message
de news:GruI83f7IHA.1620@TK2MSFTNGHUB02.phx.gbl...
Quote:
Hi Philippe ,
>
For your scenario, since you're calling an out-of-process COM object, it
will launch new COM process for new created object. To avoid this, I
agree
with Munna that you can use a global variable(such as a static class
member) to cache a single instance of the COM component instance(something
like a singleton wrapper class) and all your webservice methods will use
that one. There is several things you need to take care here:
>
1. The COM component might not be thread safe, so for such multi-threading
environment, you will need to lock it when accessing it in each thread.
I need to check...
Quote:
2. If #1 will make your performance impacted, consider creating multiple
such global instances as a pool so that you can always reuse these pooled
instances.
Good point.
Quote:
3. for .NET webservice/web application environment, the thread is MTA
thread while most COM objects are STA, this will make an additional
calling
gap between them. If the COM is really an STA one, you may need to adjust
your webservice thread's COM apartment model,[...]
Up to now I've got no problem.

So I 've added the a Global.asax file and I create the COM component in the
Application_Start as a static variable. I've also added these lines on the
Application_End method:

protected void Application_End(object sender, EventArgs e)
{
// Destroy any reference
System.Runtime.InteropServices.Marshal.ReleaseComO bject(StibilCtl);
StibilCtl = null;
}

and I think that you and Muna (which I thank also here) are absolutely
right, since now I've got only one COM object created (perhaps I will need a
pool later as yous suggest). I also have to check if I need to lock the
accesses to this object.

Thanks again

Oriane

Steven Cheng [MSFT]
Guest
 
Posts: n/a
#5: Jul 29 '08

re: Using an ActiveX in a Web service


Thanks for your followup Oriane,

Sure, if you have any further questions on this later, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Quote:
>From: "Oriane" <oriane@noemail.noemail>
>References: <4D8D6DA2-D766-4DAA-9CA1-5ED36F0F4DDA@microsoft.com>
<GruI83f7IHA.1620@TK2MSFTNGHUB02.phx.gbl>
Quote:
>In-Reply-To: <GruI83f7IHA.1620@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: Using an ActiveX in a Web service
>Date: Mon, 28 Jul 2008 08:59:49 +0200
Quote:
>
>Hi Steven,
>"Steven Cheng [MSFT]" <stcheng@online.microsoft.coma écrit dans le
message
Quote:
>de news:GruI83f7IHA.1620@TK2MSFTNGHUB02.phx.gbl...
Quote:
>Hi Philippe ,
>>
>For your scenario, since you're calling an out-of-process COM object, it
>will launch new COM process for new created object. To avoid this, I
>agree
>with Munna that you can use a global variable(such as a static class
>member) to cache a single instance of the COM component
instance(something
Quote:
Quote:
>like a singleton wrapper class) and all your webservice methods will use
>that one. There is several things you need to take care here:
>>
>1. The COM component might not be thread safe, so for such
multi-threading
Quote:
Quote:
>environment, you will need to lock it when accessing it in each thread.
>I need to check...
>
Quote:
>2. If #1 will make your performance impacted, consider creating multiple
>such global instances as a pool so that you can always reuse these pooled
>instances.
>Good point.
>
Quote:
>3. for .NET webservice/web application environment, the thread is MTA
>thread while most COM objects are STA, this will make an additional
>calling
>gap between them. If the COM is really an STA one, you may need to adjust
>your webservice thread's COM apartment model,[...]
>Up to now I've got no problem.
>
>So I 've added the a Global.asax file and I create the COM component in the
>Application_Start as a static variable. I've also added these lines on the
>Application_End method:
>
protected void Application_End(object sender, EventArgs e)
{
// Destroy any reference
>
System.Runtime.InteropServices.Marshal.ReleaseComO bject(StibilCtl);
Quote:
StibilCtl = null;
}
>
>and I think that you and Muna (which I thank also here) are absolutely
>right, since now I've got only one COM object created (perhaps I will need
a
Quote:
>pool later as yous suggest). I also have to check if I need to lock the
>accesses to this object.
>
>Thanks again
>
>Oriane
>
>
Closed Thread