Click here to Skip to main content
13,191,570 members (64,586 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 16 Dec 2002

Remote Logging using .NET Queued Components

, 16 Dec 2002
Rate this:
Please Sign up or sign in to vote.
An article on logging using .NET Queued Components.


Distributed applications almost always require a logging mechanism to log major events or errors to a logging service. These applications also require the logging solution to be highly available, reliable, and efficient.

In the following article a remote logging mechanism is discussed that uses .NET Queued Component framework for logging. .NET Queued Components provide an asynchronous, highly available, and guaranteed delivery functionality using COM+ queuing framework.

.NET Queued Components

A Queued Component is merely an object that runs asynchronously within COM+. The client of a queued component dynamically creates a proxy object for the deployed queued component. The proxy object works transparently as recorder and records all the methods invoked on the object. When released, this proxy object takes all method calls and builds a message that is sent to the server queue.

A COM+ listener at server side processes the messages in the server queue transparent to the client. It reads the message from the queue and invokes the method on the server object in the same order they were invoked at client side earlier. In case of errors during the method invocation, the method invocation is aborted and the message containing all the method calls is placed into a retry queue. If it fails on that retry, it is put into another retry queue. The intervals between retries are not configurable.

The message is placed into a special queue dead letter queue after five unsuccessful retries. Manual intervention of some type is required to successfully process or deal with such messages.

Logging classes

Proposed solution is based on a client and a server class. The sample code consists of a LogClient and LogServer class. A test application uses LogClient to log messages in LogServer queue. LogServer class inherits from ServicedComponent, which makes it run within EnterpriseServices. LogServer class also implements ILogServer interface to enable queuing support.

// LogServer Interface
public interface ILogServer
    void LogEventMessage(string logString);
    void LogExceptionMessage(string logString,byte[] arrBytes);

LogEventMessage() method logs a given message and LogExceptionMessage() method logs a given caller name and an object of ApplicationException as byte stream in log file. LogClient calls LogServer Queued Component to log messages. The client's LogEventMessage and LogExceptionMessage methods use a COM Moniker. A Moniker is a special name for a class that not only includes the class name, but also includes controlling information.

LogServer = (ILogServer) 

The .NET Framework includes a special namespace System.Runtime.InteropServices to deal with COM Interop, including COM Monikers. The Marshal.BindToMoniker method comes from the InteropServices namespace. It allows us to create an object from a COM Moniker.

MSMQ must be installed on the computer in workgroup mode in order to run the sample application. A batch file register.bat is included in the sample application package. Change this file according to your directory structure and run it to register the LogServer queue. Start the LogServer from Component Services. Now run LogServerTest application to log messages.


Marshalling between client and server component is simpler for simple types like string, integers but complex types need to implement IPersistStream interface for marshalling. I used byte stream to marshal an ApplicationException object to server.

// Convert an object to a byte array
private byte[] ObjectToByteArray(Object obj)
    if(obj == null)
        return null;
    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);
    return ms.ToArray();

At server side, un-marshalling is done by converting byte stream to an Object,

// Convert a byte array to an Object
private Object ByteArrayToObject(byte[] arrBytes)
    MemoryStream memStream = new MemoryStream();
    BinaryFormatter binForm = new BinaryFormatter();

    memStream.Write(arrBytes, 0, arrBytes.Length);
    memStream.Seek(0, SeekOrigin.Begin);

    Object obj = (Object) binForm.Deserialize(memStream);

    return obj;

Further details about .NET Queued Components can be found at MSDN. I hope this logging approach would be helpful.


  • Source code last updated - 12/16/2002


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Mohsin Khalil
Canada Canada
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralRemote Access com+ Pin
DearSoul17-Oct-06 0:21
memberDearSoul17-Oct-06 0:21 
Generaliis + msmq over http Pin
cohenraz5-Jan-06 0:58
membercohenraz5-Jan-06 0:58 
Generalneed help using client and server on seperate servers Pin
Shan McArthur3-Jul-04 11:28
memberShan McArthur3-Jul-04 11:28 
GeneralNo log file is created Pin
VMD26-Sep-03 10:12
memberVMD26-Sep-03 10:12 
GeneralRe: No log file is created Pin
Mohsin Khalil26-Sep-03 11:01
memberMohsin Khalil26-Sep-03 11:01 
GeneralRe: No log file is created Pin
Mohsin Khalil26-Sep-03 11:05
memberMohsin Khalil26-Sep-03 11:05 
GeneralNo log file is created Pin
VMD26-Sep-03 10:10
memberVMD26-Sep-03 10:10 
QuestionQueued Component over the HTTP ? Pin
Adrian Bacaianu4-Aug-03 4:03
memberAdrian Bacaianu4-Aug-03 4:03 
Generalerror message trying to register Pin
hodgear26-Feb-03 6:16
memberhodgear26-Feb-03 6:16 
I get C00E0013 trying to register this example. I think this should be a local private queue. Does anyone know how to fix this? I have mq installed and I have created local QC components in VB6 with success. I also get this in the event log:

Event Type: Error
Event Source: COM+
Event Category: (115)
Event ID: 4808
Date: 2/26/2003
Time: 12:03:16 PM
User: N/A
Computer: ARH-XP-DEV01
An unexpected error was returned by the Message Queuing API MQCreateQueue : A connection with Active Directory cannot be established. Verify that there are sufficient permissions to perform this operation.

Server Application ID: {02D4B3F1-FD88-11D1-960D-00805FC79235}
Server Application Instance ID:
Server Application Name: System Application
Error Code = 0xc00e0013 :
COM+ Services Internals Information:
File: d:\nt\com\com1x\src\comsvcs\qc\msmqrt\msmqrt.cpp, Line: 219
Comsvcs.dll file version: ENU 2001.12.4414.46 shp

For more information, see Help and Support Center at
0000: 41 00 52 00 48 00 2d 00 A.R.H.-.
0008: 58 00 50 00 2d 00 44 00 X.P.-.D.
0010: 45 00 56 00 30 00 31 00 E.V.0.1.
0018: 5c 00 4c 00 6f 00 67 00 \.L.o.g.
0020: 53 00 65 00 72 00 76 00 S.e.r.v.
0028: 65 00 72 00 e.r.

I'm not clear on why it would need to contact the AD. This should be a private queue local to the box. Thanks for any input!

QuestionSuccesses ? Pin
SteveC8826-Dec-02 4:16
memberSteveC8826-Dec-02 4:16 
AnswerRe: Successes ? Pin
Mohsin Khalil27-Dec-02 5:59
memberMohsin Khalil27-Dec-02 5:59 
GeneralRe: Successes ? Pin
SteveC8827-Dec-02 16:49
memberSteveC8827-Dec-02 16:49 
GeneralRe: Successes ? Pin
Anonymous20-Feb-03 7:30
sussAnonymous20-Feb-03 7:30 
AnswerRe: Successes ? Pin
Rosko P Coltrane10-Oct-06 0:29
memberRosko P Coltrane10-Oct-06 0:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171017.1 | Last Updated 17 Dec 2002
Article Copyright 2002 by Mohsin Khalil
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid