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;}}[assembly: ApplicationActivation(ActivationOption.Server,SoapVRoot="CSSoapSQL")]
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 10WScript.Echo i & " " & j & " " & c.CountUp("SCWKONC")nextnextC:\moniker>actscwkoMicrosoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.soap:wsdl=http://jnoss3/sctrans/SCTrans.SCTransSQLNC.soap?WSDL1 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
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; }}}set c1 = GetObject ("soap:wsdl=http://jnoss4/refpass/RefPass.Child.soap?wsdl")set c2 = GetObject ("soap:wsdl=http://jnoss4/refpass/RefPass.Child.soap?wsdl")c1.SetName("C1")WScript.Echo c1.CountUp()WScript.Echo c1.CountUp()WScript.Echo c1.CountUp()WScript.Echo c1.CountUp()WScript.Echo c1.CountUp()C2.SetName("C2")WScript.Echo c2.CountUp()WScript.Echo c2.CountUp()WScript.Echo c2.CountUp()WScript.Echo c2.CountUp()WScript.Echo c2.CountUp()C:\moniker>refpasswkoMicrosoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.none 1none 1none 1none 1none 1none 1none 1none 1none 1none 1
'直接创建两个对象set c1=CreateObject("RefPass.Child")set c2=CreateObject("RefPass.Child")'设置第一个对象的名称,并调用数次'以递增对象内部计数器c1.SetName("C1")WScript.Echo c1.CountUp()WScript.Echo c1.CountUp()WScript.Echo c1.Countup()WScript.Echo c1.CountUp()WScript.Echo c1.Countup()'设置第一个对象的名称,并调用数次'以递增对象内部计数器c2.SetName("C2")WScript.Echo c2.CountUp()WScript.Echo c2.CountUp()WScript.Echo c2.Countup()WScript.Echo c2.CountUp()WScript.Echo c2.Countup()'创建父对象set p=CreateObject("RefPass.Parent")'将子对象传递到父对象,并从父对象调用子对象WScript.Echo p.SetRef(c1)WScript.Echo p.CountUp(c2)WScript.Echo p.CountUp(c2)WScript.Echo p.CountUp(c2)WScript.Echo p.CountUp(c2)'现在调用存储在父对象内部的子对象dim c9WScript.Echo p.CountUp(c9)'从父对象获取该对象并直接调用Set c3 = p.GetRef()WScript.Echo c3.CountUp()C:\moniker>refpassclMicrosoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.C1 1C1 2C1 3C1 4C1 5C2 1C2 2C2 3C2 4C2 5C1 5C2 6C2 7C2 8C2 9C1 6C1 7
'直接创建两个对象set c1=GetObject("soap:typename=RefPass.Child,assembly=RefPass")set c2=GetObject("soap:typename=RefPass.Child,assembly=RefPass")'设置第一个对象的名称,并调用数次'以递增对象内部计数器c1.SetName("C1")WScript.Echo c1.CountUp()WScript.Echo c1.CountUp()WScript.Echo c1.Countup()WScript.Echo c1.CountUp()WScript.Echo c1.Countup()'设置第二个对象的名称,并调用数次'以递增对象内部计数器c2.SetName("C2")WScript.Echo c2.CountUp()WScript.Echo c2.CountUp()WScript.Echo c2.Countup()WScript.Echo c2.CountUp()WScript.Echo c2.Countup()'创建父对象set p=GetObject("soap:typename=RefPass.Parent,assembly=RefPass")'将子对象传递到父对象,并从父对象调用子对象WScript.Echo p.SetRef(c1)WScript.Echo p.CountUp(c2)WScript.Echo p.CountUp(c2)WScript.Echo p.CountUp(c2)WScript.Echo p.CountUp(c2)'现在调用存储在父对象内部的子对象dim c9WScript.Echo p.CountUp(c9)'从父对象获取该对象并直接调用Set c3 = p.GetRef()WScript.Echo c3.CountUp()C:\moniker>refpasscaMicrosoft (R) Windows Script Host Version 5.6Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.C1 1C1 2C1 3C1 4C1 5C2 1C2 2C2 3C2 4C2 5C1 5C2 6C2 7C2 8C2 9C1 6C1 7
Imports SystemImports System.Runtime.InteropServicesModule RefPassClSub Main()Dim ChildMoniker = "soap:assembly=RefPass,typename=RefPass.Child"Dim ParentMoniker = "soap:assembly=RefPass,typename=RefPass.Parent"Dim c1,c2,p as Objectc1 = Marshal.BindToMoniker(ChildMoniker)Console.WriteLine(c1.SetName("C1"))Console.WriteLine(c1.CountUp())Console.WriteLine(c1.CountUp())Console.WriteLine(c1.CountUp())Console.WriteLine(c1.CountUp())Console.WriteLine(c1.CountUp())c2 = Marshal.BindToMoniker(ChildMoniker)Console.WriteLine(c2.SetName("c2"))Console.WriteLine(c2.CountUp())Console.WriteLine(c2.CountUp())Console.WriteLine(c2.CountUp())Console.WriteLine(c2.CountUp())Console.WriteLine(c2.CountUp())p = Marshal.BindToMoniker(ParentMoniker)Console.WriteLine(p.SetRef(c1))Console.WriteLine(p.CountUp(c2))Console.WriteLine(p.CountUp(c2))Console.WriteLine(p.CountUp(c2))Console.WriteLine(p.CountUp(c2))Dim c9Console.WriteLine(p.CountUp(c9))Dim c3 = p.GetRef()Console.WriteLine(c3.CountUp()) End SubEnd Module……