mark.omeara

Error Connecting to the AF Server via SDK

Discussion created by mark.omeara on Jan 22, 2013
Latest reply on Sep 5, 2014 by David Hearn

I have a wcf service hosted in IIS running on the PI Server in order to access AF data, specifically Event Frames (since the official web service is still not releaseed). I have deployed the service and can bring data across quite well. For each call to the service I create a new connection, get the data, then close and dispose the connection and all related connection objects.However I notice that when I call the WCF method multiple times it will fail eventually with the error pasted below. After this error is encountered I can no longer connect to AF until I manually restart the IIS Application Pool.

 

 

 

Caught exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at OSIsoft.AF.Support.AFProxyManager.GetProxy() at OSIsoft.AF.PISystem.Connect(NetworkCredential credential, AFConnectionPreference preference)

 

Anyone have any ideas what could be causing this?

 

Tha AFSDK.DLL is 2.5.0.5039.

 

 

 

The connection code in the WCF service is similar to:

 
protected PISystem _PI = null; protected AFDatabase _AFD = null; protected AFDatabase _AFDConfiguration = null; protected OSIsoft.AF.PISystems _PISystems = new PISystems(); // Connect to the relevant PI Server _PI = _PISystems[configuration.ServerName]; System.Net.NetworkCredential oCred = new System.Net.NetworkCredential(configuration.Username, configuration.Password); // This is where it fails (usually on the third call to the wcf service)
PI.Connect(oCred); _AFD = PI.Databases[configuration.AFDatabaseName]; _AFDConfiguration = PI.Databases[configuration.AFConfigurationDatabaseName]; 

 And a disconnection is similar to:

 
_PI.Disconnect(); _PISystems.DisconnectAll(); _PI.Dispose();

 

Outcomes