/////////////////////////////////////////////////////////////////////
// C#
using System.EnterpriseServices;

ServiceConfig sc = new ServiceConfig();
sc.TrackingEnabled = true;
sc.Transaction = TransactionOption.Required;
sc.TrackingAppName = "cdecl";
sc.TrackingComponentName = "cdeclcom";

ServiceDomain.Enter(sc);

try {
    Run();
    ContextUtil.SetComplete();
}
catch (Exception ex) {
    ContextUtil.SetAbort();
}

TransactionStatus st = ServiceDomain.Leave();


/////////////////////////////////////////////////////////////////////
// C++ (native)
#include <windows.h>
#include <comsvcs.h>

IUnknown *pUnknown;
HRESULT hr = CoCreateInstance(CLSID_CServiceConfig, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&pUnknown);

IServiceInheritanceConfig *pInher;
hr = pUnknown->QueryInterface(IID_IServiceInheritanceConfig, (void**)&pInher);
hr = pInher->ContainingContextTreatment(CSC_Inherit);

IServiceTrackerConfig *pTracker;
hr = pUnknown->QueryInterface(IID_IServiceTrackerConfig, (void**)&pTracker);
hr = pTracker->TrackerConfig(CSC_UseTracker, L"CDECL_APP", L"CDECL_COM");

IServiceTransactionConfig *pTran;
hr = pUnknown->QueryInterface(IID_IServiceTransactionConfig, (void**)&pTran);
hr = pTran->ConfigureTransaction(CSC_NewTransaction);
hr = pTran->IsolationLevel(COMAdminTxIsolationLevelReadUnCommitted);

CoEnterServiceDomain(pUnknown);

IObjectContext *ctx;
hr = GetObjectContext(&ctx);

try {
    Run();
    ctx->SetComplete();
}
catch (...) {
    ctx->SetAbort();
    cout << "Unknown Exception " << endl;
}

ctx->Release();

CoLeaveServiceDomain(pUnknown);

pTran->Release();
pTracker->Release();
pInher->Release();
pUnknown->Release();



'Dev > Windows' 카테고리의 다른 글

SQLOLEDB Provider 의 특이한 동작  (0) 2007.09.20
COM+ Queued Components  (0) 2007.08.09
RestartService  (0) 2007.07.19
MultiMedia Timer  (0) 2007.05.14
.NET Enterprise Services 성능 ( vs COM+)  (0) 2007.05.14

+ Recent posts