COM+ Web 服務(wù):通過復(fù)選框路由到 XML Web Services (轉(zhuǎn))6
2024-09-05 20:55:50
供稿:網(wǎng)友
要建立并運(yùn)行此 c# 組件,在完成編輯連接值以連接到 microsoft sql server™ 數(shù)據(jù)庫之后,需要使用 sn.exe 生成 sctrans.snk 加強(qiáng)名稱關(guān)鍵字文件,然后在 using 語句中使用程序集引用對其進(jìn)行編譯。如果您在服務(wù)器上進(jìn)行部署,應(yīng)使用 gacutil.exe(如果正在使用 sdk)或通過 .net 框架用戶界面將程序集放入 gac,然后運(yùn)行 regsvcs.exe,注冊 com+ 托管組件。regsvcs.exe 將使用以下屬性,將組件發(fā)布為服務(wù)器上的 soap 端點(diǎn)和服務(wù)器(進(jìn)程外)激活:
[assembly: applicationactivation(activationoption.server,
soapvroot="cssoapsql")]
此組件在每種方法調(diào)用中使用不同的事務(wù),具有一個(gè)自動(dòng)完成方法,并被配置為進(jìn)行緩沖。使用托管和非托管 com+ 組件時(shí),對象池和事務(wù)將如所預(yù)期的那樣通過 soap 運(yùn)行。例如,如果使用下列 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
將顯示以下輸出內(nèi)容:
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
這就是所預(yù)期的緩沖的組件:從緩沖池中拖出對象并重新使用。使用客戶端激活的緩沖組件的行為都是相同的。
非托管組件的對象池和事務(wù)也如所預(yù)期的那樣運(yùn)行(雖然 visual basic 6.0 組件不支持對象池)。需要為大多數(shù)非托管應(yīng)用程序通過 com+ 管理工具設(shè)置緩沖和事務(wù)屬性。
傳遞引用
wko 與 cao 模型的一個(gè)關(guān)鍵區(qū)別在于它們向有狀態(tài)的對象傳遞引用的能力。以下是 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# 程序有兩個(gè)類:child 和 parent