Ask a questionAsk a question
 

AnswerCalling STA COM component from WCF.

  • Saturday, November 07, 2009 9:23 AMtomer70 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

     

    I have a VB STA com component and I use it as follows

     

    public class Service1 : IService1

    {

            private ProjectSTA.ClassSTA x; ‘VB6 STA Component

     

            public string GetData(int value)

            {

             Console.Write(Thread.CurrentThread.GetApartmentState().ToString()); 'return MTA

                return x.GetName();

     

           }

    }

     

    public CompositeType GetDataUsingDataContract(CompositeType composite)

    {

                x = new ProjectSTA.ClassSTA();

    }

            

     

     

    Reading many articles I was expecting that it will fail since the service is run under MTA?!

    I am using VS.NET 2010

    Thanks in advance

Answers

  • Sunday, November 08, 2009 1:10 AMHaripraghash Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    When WCF calls a com object it effectivey blocks all other calls to the WCF service until that com call completes, effectively becoming single threaded! 

    Even though WCF is MTA the MTA threads have to wait till the STA com call completes.One option is to expose COM+ component as a WCF service ,so we can use this option to communicate with COM+ component.


    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    • Proposed As Answer byHaripraghash Sunday, November 08, 2009 1:10 AM
    • Marked As Answer bytomer70 Sunday, November 08, 2009 7:26 AM
    •  

All Replies

  • Saturday, November 07, 2009 11:19 AMtomer70 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     


    Looks like the STA component is created in a different thread(the default thread created by com?)

    Tomer

  • Saturday, November 07, 2009 12:28 PMtomer70 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I think i understand....

    .NET will correctly marshal calls from MTA to STA, the problem is that If several COM components is used by the

    Service all calls to ALL components will be serialized through a single thread

    So all parallelism is lost.

     

    Can any one confirm this?

  • Sunday, November 08, 2009 1:10 AMHaripraghash Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    When WCF calls a com object it effectivey blocks all other calls to the WCF service until that com call completes, effectively becoming single threaded! 

    Even though WCF is MTA the MTA threads have to wait till the STA com call completes.One option is to expose COM+ component as a WCF service ,so we can use this option to communicate with COM+ component.


    Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/
    • Proposed As Answer byHaripraghash Sunday, November 08, 2009 1:10 AM
    • Marked As Answer bytomer70 Sunday, November 08, 2009 7:26 AM
    •