Wednesday, September 29, 2021

Transform COM+ serviced component to WCF Service

With the advent of WCF, there is a paradigm shift in developing applications interacting across network. However porting existing COM based applications to WCF architecture can be daunting task. A balance can be achieved by deploying existing COM based applications as a WCF service so that it can be accessed by WCF clients.

Any COM component can be simply made as a WCF service using he LBGenrator.Following defines the process.
1.      Select COM components as described in DCOM Client
2.      Navigate to WCF Server tab, enter a namespace for the generated wrapper class
3.      The Generate Code option does following
a.       Scan through the selected COM objects and generate an Interface for each
b.      A project is created containing a COM object COM_LB_<prog id> that implements ServicedComponent and the interface
c.       This project is compiled and wcfserver.dll is generated and copied to wcfserver.dll

Example
As described in the previous post, use sillycalc.wsc. Copy the code and save it to sillycalc.wsc and register it.
Load the WCF component in a COM+ Application as discussed in the previous post.


 
Load  the wsc file as shown below and generate wcfserver.dll from WCF Server tab. This contains a COM class implementing wcf service. wcfserver.COM_LB_SillyCalc_WSC_1. 
Copy wcfserver.dll from the output folder and Execute following command to deploy  WCF service.

ComAppHelper -ins -app:wcfcalc  -gac -runforever -svc  D:\Github\TechBlog\COM+\WSC\wcf_client\wcfserver.dll


WCF Client

Create a console project and add a service reference for address net.pipe://localhost/wcfcalc/wcfserver.COM_LB_SillyCalc_WSC_1/mex



The app.config needs be edited to comment as below:
       
	   
<!--
<identity>
<userPrincipalName value="VEDAVYASARAO\rvvya" />
</identity>
-->

 
 

Consume the service as below
       
	   
static void Main(string[] args)
{
    var x = new ServiceReference1.SillyCalc_WSC_1Client();
    Console.WriteLine("calling x.add(10, 2) Result:{0}", x.add(10, 2));
    Console.ReadKey();
}

 
 

Result



Adding a  different service endpoints to WCF service
Currently the installer deploys a named pipes endpoint. Additional endpoint such as net.tcp can be easily added using “SCConfiguration Editor”(svcConfigEditor.exe ) as shown below.

  1.         Open the COM+ application from File->Open->COM+ Application.
  2.         Select WCFCalc Application

.     



   3      3. Add a new service point as shown below.


Similarly Managed COM component CalcServer.Calucalator, hosted in a COM+ application can be utilized as  a WCF service.


Source and Binaries can be found here.





No comments:

Post a Comment