Server
Using system;using system.collections.generic;using system.linq;using system.text;using System.EnterpriseServices;using System.Runtime.InteropServices; [Assembly: applicationname ("Hunjixinservicestransactiontest")]//name in the Component Services browser [assembly: Description ("coded by ljli 2/14/2009")]//description information in the Component Services browser [assembly: ApplicationActivation (activationoption.server)]//Startup Type the library activates in the creation process, runs in the client process, the Server type system [assembly: applicationaccesscontrol (FALSE)]//access settings, when off, users can access namespace EnterpriseServicesCOMTest{ [eventtrackingenabled (true)]//allows monitoring, which the Component Object Browser can see. is turned off by default because it degrades performance [description ("coded by frankljl for Enterpriseservices cacular test ")]//the description information displayed by the Component Object Browser //[ JustInTimeActivation (False)]//turns on or off the JIT start [objectpooling (true, 1,  10)]//whether to enable object pooling, such asFruit object creation consumes more resources, you can consider whether the object pool [transaction (transactionoption.supported)]//need to support transactional attributes public class Cacu : ServicedComponent { public cacu ()    { }        PUBLIC STRING FUC () { return "Subtraction Operation"; } public int add (int x, int y) { return x + y; } Public int sub (int x, int y) { return x - y; } public int mul (int x, int y) { return x * y; } public int div (int x, int y) { if (y != 0) { return x / y; &nbsP; } else { throw new notfinitenumberexception (" Divisor cannot be zero "); } } }}
Here's a place to be aware that ComVisible needs to be set to visible, otherwise the registration will fail.
Set ComVisible to False to make the types///COM components in this assembly invisible. If you need to access a type from COM in this assembly,//sets the ComVisible attribute on that type to true. [Assembly:comvisible (True)]
Call
Using system;using system.collections.generic;using system.linq;using system.text;using system.enterpriseservices;using enterpriseservicescomtest;namespace enterpriseservicesclient{ class Program { static void main (String[] args) { using (Enterpriseservicescomtest.cacu ca = new cacu ()) { Console.WriteLine (Ca.fuc ()); console.writeline (Ca.add (12, 13));   Console.WriteLine (Ca.sub (12, 13)); console.writeline (Ca.mul (12, 13)); console.writeline (Ca.div (12, 13)); } } }}
WCF Learning Journey----The EnterpriseServices of basic articles