Standalone .NET Events client throws nullreference; also write issues to the database

Programs Affected: OpenSpan Events 4.5


Description

One OpenSpan developer used a .NET-generated client to send in events from a separately-built Windows service to log all processes that are started and stopped - a basic, no-touch events system. There were problems, however, getting the event server to write the event out to the database. It threw a nullreference but didn't give any more information.

The developer was using MSSQL server, and a Web service connection, a client built with Visual Studio from the WSDL.

Here is the code example from Visual Studio.




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using MonitorProcesses.OpenSpanEvents;
using System.ServiceModel.Description;
 
namespace MonitorProcesses
{
    public class OpenSpanEventHelper
    {
        public static void SendEvent(DateTime eventTime, string timezone, string eventName)
        {
            NotificationServiceClient c = new NotificationServiceClient("OSWsHttp");
            EventOccurredArgs args = new EventOccurredArgs();
            args.mEventType = EventType.Generic;
            args.mEventTimeStamp = eventTime;
            args.mEventName = eventName;
            args.mTimeZoneName = timezone;
            c.SendNotification(args);
        }
    }
}

The possible solutions examined possible serialization problems. It was finally determined that the issue can be worked around by adding initialization code prior to sending an EventOccurredArgs() object to the server, as follows:



EventOccurredArgs a = new EventOccurredArgs();
a.mEventType = EventType.Generic;
a.mEventTimeStamp = eventTime.ToUniversalTime();   // this must be in UTC
a.mEventName = eventName;
a.mTimeZoneName = timeZone;
// add initialization to dictionaries in the type
a.AttributeNameValues = new Dictionary< string, object>();
a.DimensionNameValues = new Dictionary< string, object>();
a.FactNameValues = new Dictionary< string, object>();
a.MetadataNameValues = new Dictionary< string, object>();
// add an interlocked increment of static long to ensure sequencing from client.
a.mEventSequenceNumber = Interlocked.Increment(ref mSafeEventSequence);

Note on the code above as displayed: formatting for this Web article requires a space after the left angle brackets ( < ) above. If you copy the code swatch, please delete the spaces in your development tools. There are four spaces.

The future may well bring some more code server-sde to make up for this. OpenSpan development is likewise tracking possible changes such that a generated class via the WSDL would do the initialization to force timestamp to UTC and allow for auto sequencing.

Article is in the following categories:
KB » Events Server» Install and Configure


Leave A Comment

or close

Email This Article

or close