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.

The following procedure requires you to add additional assembly references to the form.  Any additional references should be added through the Designer to ensure that they are added properly. If a reference is added in Visual Studio, be absolutely certain that you set the CopyLocal and SpecificVersion attributes to false or the form may not be useable with future product releases.

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.