Ruminations of idle rants and ramblings of a code monkey

StreamInsight: Simple sample of adapters and Server.Connect

.NET Stuff | StreamInsight | Code Sample

This is in response to a question on the StreamInsight forum where a developer was asking for a sample that uses Server.Connect.

Before I get into the details, notes:

  • I used the PatternDetector sample from the StreamInsight Product Team Samples on CodePlex. Rather than write something from scratch, I just converted the existing project to VS 2010 and tweaked it.
  • Add a reference to System.ServiceModel to the project.
  • You need to make sure that you defined an instance for StreamInsight in the setup and installed the service. And start it. Starting it helps.
  • I had to change the creds for the StreamInsight service to use my credentials instead of Network Service because I got a funky error (that I’ve never seen before) with the Event Flow Debugger. It may have something to do with the fact that I’m running on a domain controller (don’t say it … I know … but it’s just a dev machine and I need to AD for some Hyper-V VM’s that I run). I’d recommend trying to do it with Network Service but if it doesn’t work, you’ve been warned. The error is below:

Security Support Provider Interface (SSPI) authentication failed. The server may not be running in an account with identity 'DEVBIKER\J Sawyer'. If the server is running in a service account (Network Service for example), specify the account's ServicePrincipalName as the identity in the EndpointAddress for the server. If the server is running in a user account, specify the account's UserPrincipalName as the identity in the EndpointAddress for the server.

  • You need to make sure that you copy the relevant DLL’s to the folder for the StreamInsight service host folder. By default, this is C:\Program Files\Microsoft StreamInsight 1.1\Host. These can be found in the \bin folder for the PatternDetector project and are:
    • StreamInsight.Samples.Adapters.SimpleTextFileReader
    • StreamInsight.Samples.Adapters.SimpleTextFileWriter
    • StreamInsight.Samples.UserExtensions.Afa
  • Create a folder for the input and output folders. Actually, if you are running under your own account, this won’t be necessary. If you are running under Network Service, you will. And make sure that you give Network Service appropriate permissions.
  • The User Defined Operator in the sample that I chose caused an issue when running remotely. This surprised me … usually things run pretty much unchanged. I didn’t have the time or energy to debug that so I just changed it so that it was no longer necessary.

So … the changes.

In void Main, I changed the startup code to:

if (inProc)
using (Server server = Server.Create(streamInsightInstanceName))
using (Server server = Server.Connect(new System.ServiceModel.EndpointAddress("http://localhost/StreamInsight/" + streamInsightInstanceName)))


As you can see, I refactored everything in the using block to a new method called “RunApp”. This made it cleaner (I thought). I suppose that I could have done it another way, but this just seemed right.

In RunApp, I changed to code to create the application to check for the existence of the application and, based on that, get or create the application object. This is below:

// Create application in the server. The application will serve 
// as a container for actual CEP objects and queries.Console.WriteLine("Creating CEP Application");Application application;if (!server.Applications.ContainsKey(appName))
application = server.CreateApplication(appName);
application = server.Applications[appName];

And that is (typically) all that you need to do to change a StreamInsight app to run either in proc or remote. As I mentioned before, I did have to change the query and remove the reference to the UDO … which was very strange because I’ve never had issues with extensions before. I’m guessing that it had something to do with the implementation of the UDO.

You can download it below Program.cs (the only changed file) for the Pattern Detector sample below: