
|
导读要建立并运行此 C# 组件,在完成编辑连接值以连接到 Microsoft SQL Server 数据库之后,需要使用 sn.exe 生成 sctrans.snk 加强名称关键字文件,然后在 usin... 要建立并运行此 C# 组件,在完成编辑连接值以连接到 Microsoft SQL Server™ 数据库之后,需要使用 sn.exe 生成 sctrans.snk 加强名称关键字文件,然后在 using 语句中使用程序集引用对其进行编译。如果您在服务器上进行部署,应使用 gacutil.exe(如果正在使用 SDK)或通过 .NET 框架用户界面将程序集放入 GAC,然后运行 regsvcs.exe,注册 COM+ 托管组件。Regsvcs.exe 将使用以下属性,将组件发布为服务器上的 SOAP 端点和服务器(进程外)激活:[assembly: ApplicationActivation(ActivationOption.Server, SoapVRoot="CSSoapSQL")] 此组件在每种方法调用中使用不同的事务,具有一个自动完成方法,并被配置为进行缓冲。使用托管和非托管 COM+ 组件时,对象池和事务将如所预期的那样通过 SOAP 运行。例如,如果使用下列 VBScript 通过 SOAP 访问以下 ServicedComponent: mon = "soap:wsdl=http://jnoss3/sctrans/SCTrans.SCTransSQLNC.soap?WSDL" WScript.Echo(mon) for i = 1 to 2 set c = GetObject(mon) for j = 1 to 10 WScript.Echo i & " " & j & " " & c.CountUp("SCWKONC") next next 将显示以下输出内容: C:\moniker>actscwko Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. soap:wsdl=http://jnoss3/sctrans/SCTrans.SCTransSQLNC.soap?WSDL 1 1 486 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 1 2 487 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 1 3 488 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 1 4 489 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 1 5 490 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 1 68 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 1 79 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 1 8 10 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 1 9 494 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 1 10 495 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 2 1 13 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 2 2 14 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 2 3 15 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 2 4 499 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 2 5 17 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 2 6 501 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 2 7 502 NC 6e41f32f-74be-45f0-94c0-989e7e1c5672 2 8 19 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 2 9 20 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 2 10 21 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce 这就是所预期的缓冲的组件:从缓冲池中拖出对象并重新使用。使用客户端激活的缓冲组件的行为都是相同的。 非托管组件的对象池和事务也如所预期的那样运行(虽然 Visual Basic 6.0 组件不支持对象池)。需要为大多数非托管应用程序通过 COM+ 管理工具设置缓冲和事务属性。 传递引用 WKO 与 CAO 模型的一个关键区别在于它们向有状态的对象传递引用的能力。以下是 C# ServicedComponent 示例,显示了此操作的基本步骤: using System; using System.Reflection; using System.EnterpriseServices; using System.Runtime.InteropServices; [assembly: ApplicationName("RefPass")] [assembly: ApplicationActivation(ActivationOption.Server, SoapVRoot="RefPass")] [assembly: AssemblyKeyFile("RefPass.snk")] namespace RefPass { public interface IParent { string SetRef(object inKid); object GetRef(); string CountUp(object obj); } public interface IChild { string GetValue (); string CountUp(); void SetName(string key); } [ClassInterface(ClassInterfaceType.AutoDual)] public class Parent: ServicedComponent, IParent { protected Child _kid = null; public string SetRef(object inKid) { _kid = (Child)inKid; return _kid.GetValue(); } public object GetRef() { return (object)_kid; } public string CountUp(object obj) { Child kid = (Child)obj; if (kid == null) return _kid.CountUp(); else return kid.CountUp(); } } [ClassInterface(ClassInterfaceType.AutoDual)] public class Child : ServicedComponent, IChild { private int _counter = 0; private string _name = "none"; public string CountUp() { _counter++; return GetValue(); } public string GetValue() { return (_name + " " +_counter.ToString()); } public void SetName(string key) { _name = key; } } } 此 C# 程序有两个类:Child 和 Parent |
温馨提示:喜欢本站的话,请收藏一下本站!