Exposing COM+ Application to WCF Service
Exposing COM+ Application to WCF Service
By : Kasim Wirama, MCDBA, MVP SQL Server
If you’ve deployed COM+ application for your organization, you have chance to expose the COM+ application to WCF service as well. WCF service will wrap your COM+ application so that it can be called as WCF service.
I will give you demo how to create COM+ application and expose it to WCF service.
Create COM+ application
You need to define at least a contract and a contract implementation, and mark the interface with attribute COMVisible to true, and assign guid to the interface through attribute. If you define class domain, you need to apply attribute Serializable to the class domain. For class implementation, decorate it with 2 attribute, ClassInterface and Transaction attribute. Besides that, the interface implementation class inherits ServicedComponent from namespace System.EnterpriseServices. In COM+ project, include reference to Service.EnterpriseServices. You need to set ComVisible on project property, sign the project with strong name file, because you need to deploy it to gac. I name the class library project as Order.
Here the script sample
[Serializable()]
public class Order
{
public int orderID;
public string productName;
public int quantity;
}
[ComVisible(true)]
[Guid("12E10CAB-D11A-4058-92C7-F42A7BFB0ACF")]
public interface IService
{
ICollection<int> GetListID();
Order GetOrder(int orderID);
}
[ClassInterface(ClassInterfaceType.None)]
[Transaction(TransactionOption.Supported)]
public class Service : System.EnterpriseServices.ServicedComponent, IService
{
public ICollection<int> GetListID()
{
int[] orderListID = { 1, 2, 3 };
return orderListID;
}
public Order GetOrder(int orderID)
{
Order order;
if (orderID == 1)
{
order = new Order { orderID = 1, productName = "milk", quantity = 2 };
}
else if (orderID == 2)
{
order = new Order { orderID = 1, productName = "bread", quantity = 2 };
}
else
{
order = new Order { orderID = 1, productName = "beer", quantity = 2 };
}
return order;
}
}
Build the project, and deploy it to gac with gacutil /I Order.dll.
Next task is to deploy the component as COM+ application, type in command prompt dcomcnfg, expand to My Computer/COM+ applications, create new application, give name to the new COM+ application, in new COM+ application expand Components folder, choose New Component with option Install New component(s) and browse to the registered DLL.
Exposing COM+ application as WCF Service
Here the second big step is to expose your COM+ application as WCF service. It is very simple, because there is no coding involved, with just set up in app.config of the project. Open the app.config with Service Configuration Editor program, choose File menu then Integrate -> COM+ Applications, select the component interface, in this sample is IService. Choose the type of hosting as COM+ hosted, and HTTP as communication mode, and specify its base address for your WCF service, for example http://localhost:8777/test, and it is done. Next is open the WCF service, through File menu, then Open -> COM+ service, select the just created COM+ service. You can verify all the properties within the configuration for COM+ application. COM+ related configuration will be saved in subfolder with GUID name in C:\Program Files\Complus Applications. There is application.config file. Using browser, browse to http://localhost:8777/test, you will get your WCF up and running