Use a service provider method exclusively in code

Most service provider methods are accessible and can be configured using Service Provider Methods. For those that are not accessible, follow the tips in this topic for assistance.

Important: The following procedure requires the adding of 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, ensure that the CopyLocal value = false and the SpecificVersion value = false or the form may not be useable with future product releases.
In most cases, the required Service Provider methods, including those from custom providers, are accessible and can be configured through the Server Methods dialog. However, if a method is configured with the Browsable attribute set to False, it does not appear in the Server Methods dialog, and it can only be accessed through code.

In Designer-generated forms or user displays, access the IServiceDirectory service from the host as follows:

IServiceDirectory serviceDirectory = this.Host.GetService(typeof(IServiceDirectory)) as IServiceDirectory;

You must have an assembly reference to Proficy.Platform.Core.ClientTools.ServiceDirectory.Interfaces.IServiceDirectory.dll and the assembly containing the Service Provider interface you want to access. Additionally, have a using statement for Proficy.Platform.Core.ClientTools.ServiceDirectory.Interfaces and the 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(typeof(ICustomSP).FullName) as ICustomSP; Proficy.Platform.Forms.Editor.CustomControls.UniversalBrowser browser = UniversalBrowser1; int result = equipmentSP.QueryPropertyCount(browser.SelectedItem as DirectoryResource,"%"); TextBox tb = TextBox1; tb.Text= result.ToString();

For this code to work, add an assembly reference to Proficy.Platform.Services.EquipmentInterfaces.dll. Also add the following using statements:

  • using Proficy.Platform.Services.Equipment.Interfaces
  • using Proficy.Platform.Core.ProficySystem.Types

For a custom service provider, add the appropriate assembly and namespace references.