Tuesday, March 22, 2005 1:29 PM
distilled
COM+ to Indigo: The "no new code" aproach
I’d like to present a complete example showing how the COM+ Integration feature of Indigo can be used to take and existing COM+/Enterprise Services class and expose its interface as a web service.
Consider first a very typical Enterprise Services class that contains some business logic:
using System;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
[assembly: ApplicationName("IndigoSample")]
[assembly: ApplicationID("E146E066-D3D1-4e0e-B175-30160BD368DE")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(false, AccessChecksLevel = AccessChecksLevelOption.Application)]
namespace Microsoft.Samples.Indigo.Samples
{
[Guid("C551FBA9-E3AA-4272-8C2A-84BD8D290AC7")]
public interface ICalculator
{
double Add(double n1, double n2);
double Subtract(double n1, double n2);
double Multiply(double n1, double n2);
double Divide(double n1, double n2);
}
[Guid("BE62FF5B-8B53-476b-A385-0F66043049F6")]
[ProgId("IndigoSample.esCalculator")]
public class esCalculator : ServicedComponent, ICalculator
{
public double Add(double n1, double n2)
{
return n1 + n2;
}
public double Subtract(double n1, double n2)
{
return n1 - n2;
}
public double Multiply(double n1, double n2)
{
return n1 * n2;
}
public double Divide(double n1, double n2)
{
return n1 / n2;
}
}
}
To go from this to a fully registered COM+ application requires a few standard steps:
-
Create a project with this and build a strong named assembly – this will require generating a key with the Strong Name Utility and use of the appropriate compiler switch.
-
Add the assembly to the Global Assembly Cache e.g. gacutil /i esCalculator.dll
-
Register the assembly’s component and the “IndigoSample” application with COM+ e.g. regsvcs esCalculator.dll
At this point we have our COM+ application, ready to accept calls from COM & DCOM clients and absolutely no web service capabilities.
We can now continue to add web services, assuming of course that you are using a machine with the CTP release of Indigo installed. At the command prompt enter:
ComSvcConfig add /application:IndigoSample
/interface:IndigoSample.esCalculator,ICalculator /hosting:complus
And we’re done. At this point, the ICalculator interface of this application is now exposed as rich interoperable WS-* web service hosted within the COM+ container.
In future posts I’ll detail how this is achieved (note that the Indigo CTP did not modify COM+) along with details on how you can configure, connect to and use this service.