System.Security.SecurityException: Request for the permission of type System.Security.Permissions.SecurityPermission failed.

WCF service Pieserver is hosted in IIS 7.5. It is using wshttpbinding.
client : console application.

We are able to add the service reference but get the exception below when we call any methods on the proxy object :

Error Message: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: The type initializer for 'OSIsoft.RtBaseline.DataService.ServerManager' threw an exception.
System.TypeInitializationException: The type initializer for 'OSIsoft.RtBaseline.DataService.ServerManager' threw an exception. ----> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.Principal.WindowsIdentity.GetCurrent() at OSIsoft.PIInstrumentation.LogWriter.WriteToEventLog(String source, String message, EventLogEntryType elType)
at OSIsoft.PIInstrumentation.LogWriter.WriteGeneralEventLog(String source, String message, Severity svrty, Boolean CheckSuppression) at OSIsoft.PIInstrumentation.RtBLSConfig.get_Setting() at OSIsoft.RtBaseline.DataService.ServerManager..cctor() --- End of inner ExceptionDetail stack trace --- at OSIsoft.RtBaseline.DataService.ServerManager.SetApplicationID(String appID) at PIWebServices.PID...). For more information, see Help and Support Center at

The WCF service application files were hosted on a network share. CAS (Code Access Security) policy has been applied for the service. The PIWebServices.dll is trying to get the current windows identity and failing because the defined CAS policy does not grant ControlPrincipal permissions to it. To provide the permissions on the network share we ran the command below:

CasPol.exe -m -ag 1.2 -url file://\\* FullTrust


Using CasPol to Fully Trust a Share