Using a Service Provider Method Exclusively in Code
Service provider methods, including those from custom service providers, are, in most cases, accessible and can be configured using the Server Method dialog box in the Designer. However, if a method is configured with the Browsable attribute set to False, then it will not show up in the Server Methods dialog box and can be accessed only through code.
In forms or user displays generated in the Designer, you can access the IServiceDirectory service from the Host as follows:
IServiceDirectory serviceDirectory = this.Host.GetService(typeof(IServiceDirectory)) as IServiceDirectory;
This requires an assembly reference to Proficy.Platform.Core.ClientTools.Interfaces.IServiceDirectory.dll, and the assembly containing the Service Provider interface you want to access. Additionally, you require a using statement for Proficy.Platform.Core.ClientTools.ServiceDirectory.Interfaces, as well as your Service Provider interface.
The IServiceDirectory service provides access to service providers through their interface names, as follows:
ICustomSP someCustomSP = serviceDirectory.CreateLogicalServiceProxy(typeof(ICustomSP).FullName) as ICustomSP;
For example, an IEquipment Service Provider method can be executed with the following code:
IEquipment equipmentSP = serviceDirectory.CreateLogicalServiceProxy(EquipmentInterfaceNames.EQUIPMENT_IEQUIPMENT) as IEquipment;
Proficy.Platform.Forms.Editor.CustomControls.UniversalBrowser browser = UniversalBrowser1;
int result = equipmentSP.QueryPropertyCount(browser.SelectedItem as DirectoryResource,"%");
TextBox tb = TextBox1;
tb.Text = result.ToString();
To get this to work, you must add an assembly reference to Proficy.Platform.Services.EquipmentInterfaces.dll, and the following using statements:
- using Proflicy.Platform.Services.Equipment.Interfaces;
- using Proficy.Platform.Core.ProficySystem.Types;
For a custom Service Provider, you require the appropriate assembly and namespace references.