COM+ Web 服務:通過複選框路由到 XML Web Services (轉)6
最後更新:2017-02-28
來源:互聯網
上載者:User
services|web|xml|複選框 要建立並運行此 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 6 8 NC af26b53b-4a1f-48c8-8880-518c2b55a7ce
1 7 9 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