最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
COM+ Web 服务:通过复选框路由到 XML Web Services(2) (微软中国)
时间:2022-07-02 11:22:01 编辑:袖梨 来源:一聚教程网
事务性组件示例
简单的计算器远算不上工作量繁重的业务应用程序,因此我们现在考虑带有对象池的适于 COM+ 事务性组件的应用程序。
最容易管理和配置的组件是由 ServicedComponent 导出的托管代码组件,如以下 C# 示例所示:using System;using System.Reflection;using System.Runtime.InteropServices;using System.EnterpriseServices;using System.Data;using System.Data.SqlClient;[assembly: ApplicationName("SCTrans")][assembly: ApplicationActivation(ActivationOption.Server, SoapVRoot="SCTrans")][assembly: AssemblyKeyFile("SCTrans.snk")]namespace SCTrans{ public interface ISCTrans { string CountUp (string Key); } [ObjectPooling(MinPoolSize=0, MaxPoolSize=25)] [JustInTimeActivation(true)] [ClassInterface(ClassInterfaceType.AutoDual)] [TransactionAttribute(TransactionOption.RequiresNew)] public class SCTransSQLNC : ServicedComponent, ISCTrans { [AutoComplete] public string CountUp (string Key) { _command = new SqlCommand("", _connection); _command.CommandType = CommandType.Text; _command.Connection.Open(); _command.CommandText = "UPDATE CallCount WITH (ROWLOCK) SET CallCount = CallCount + 1 WHERE Machine='" + Key + "'"; _command.ExecuteNonQuery(); _command.Connection.Close(); _numcalls++; return (_numcalls + " NC " + _guid); } protected override bool CanBePooled() { return true; } private int _numcalls = 0; private string _guid = Guid.NewGuid().ToString(); private SqlConnection _connection = new SqlConnection("user id=MyUser;password=My!Password; database=SoapTest;server=MyServer"); private SqlCommand _command; }}
简单的计算器远算不上工作量繁重的业务应用程序,因此我们现在考虑带有对象池的适于 COM+ 事务性组件的应用程序。
最容易管理和配置的组件是由 ServicedComponent 导出的托管代码组件,如以下 C# 示例所示:using System;using System.Reflection;using System.Runtime.InteropServices;using System.EnterpriseServices;using System.Data;using System.Data.SqlClient;[assembly: ApplicationName("SCTrans")][assembly: ApplicationActivation(ActivationOption.Server, SoapVRoot="SCTrans")][assembly: AssemblyKeyFile("SCTrans.snk")]namespace SCTrans{ public interface ISCTrans { string CountUp (string Key); } [ObjectPooling(MinPoolSize=0, MaxPoolSize=25)] [JustInTimeActivation(true)] [ClassInterface(ClassInterfaceType.AutoDual)] [TransactionAttribute(TransactionOption.RequiresNew)] public class SCTransSQLNC : ServicedComponent, ISCTrans { [AutoComplete] public string CountUp (string Key) { _command = new SqlCommand("", _connection); _command.CommandType = CommandType.Text; _command.Connection.Open(); _command.CommandText = "UPDATE CallCount WITH (ROWLOCK) SET CallCount = CallCount + 1 WHERE Machine='" + Key + "'"; _command.ExecuteNonQuery(); _command.Connection.Close(); _numcalls++; return (_numcalls + " NC " + _guid); } protected override bool CanBePooled() { return true; } private int _numcalls = 0; private string _guid = Guid.NewGuid().ToString(); private SqlConnection _connection = new SqlConnection("user id=MyUser;password=My!Password; database=SoapTest;server=MyServer"); private SqlCommand _command; }}
相关文章
- 云星穹铁道权益升级怎么玩 云崩铁权益升级活动介绍 12-03
- 以闪亮之名山中绘梦怎么玩 以闪亮之名滢然花梦套装活动介绍 12-03
- 以闪亮之名绿野梦歌礼包怎么样 以闪亮之名绿野梦歌拍照礼包介绍 12-03
- 光遇12.6有什么更新 光遇12月6日更新内容介绍 12-03
- 伍六七暗影交锋测试资格怎么获得 伍六七暗影交锋内测资格获取方法 12-03
- 无限暖暖晶莹诗集怎么样 12-03