A Static Service Broker is used when the underlying Schema of the provider does not change frequently. Think of a Static Broker as something that describes the Service Objects (as opposed to dynamically discovering Service Objects by querying some underlying schema), because it always knows what the Provider's schema looks like.
Here is an example: suppose you have a class library in your organization that exposes Time Zone information. This TimeZone object has properties like Name, UTCOffset and Abbreviation and methods like Read TimeZone and List TimeZones. We don’t expect that the definition or Schema of the TimeZone object will ever change. Now imagine that we wanted to create a Service Broker that exposes this custom TimeZone object so that we can create SmartObjects for TimeZones. Since the Schema of our TimeZone object never changes, we can create a static Service Broker which describes the TimeZone as a Service Object. Essentially, the description of the Service Object is hard-coded into the Service Broker code.
Here are the basic steps to implement a Static Service Broker:
Custom Brokers are standard .NET Class libraries (.dlls). You can create a Service Broker in C# or VB.NET. If you have an existing class that you want to expose as a Service Broker, you can edit the code in your class and add the necessary decorations or alternatively reference your assembly in a new class project. If you are referencing a custom assembly, remember that you will need to copy the references assembly to the K2 server along with the Service Broker .dll file.
Add a reference to the .NET library SourceCode.SmartObjects.Services.ServiceSDK.dll which is located by default in C:\Program Files (x86)\K2 blackpearl\Bin. This file is available on the K2 server and in a machine where the K2 design tools are installed. When deploying your project you don’t need to copy this assembly to the K2 server, since it already exists on the K2 server.
After adding the reference, import the SourceCode namespaces that you will need to use in your project:
Next inherit the base class SourceCode.SmartObjects.Services.ServiceSDK.ServiceAssemblyBase in your project. We recommend creating a separate .cs class for the base class to separate the Broker code implementation from the class you will expose as a ServiceObject.
When you inherit this base class in your class, you will override two methods for your service broker: GetConfigurationand DescribeSchema.
Importing required namespaces and inheriting from the base class:
The next step is to add any configuration settings to your broker, if you need to store configuration settings per Service Instance. You do this by overriding and implementing the base class' GetConfigSection() method. For each configuration setting in your Service Broker, add it to the Service Configuration items like this:
Implementing configuration settings:
At runtime, you can expose the Service Instance's configuration settings by declaring a property of type ServiceConfiguration in your class. K2 will automatically pass the service instance configuration settings into this property at runtime. You can read the configuration values like this:
Obtaining Service Instance configuration settings at runtime:
Next, you need to define the Service Objects in your Broker. Since this is a Static or Described schema broker, you will achieve this by adding Attribute descriptors to the Classes, Properties and Methods in your class file.
If necessary, create a public .NET Class for each Service Object in your new Broker. Decorate the classes that you want to expose as Service Objects with the [Attributes.ServiceObject] attribute.
Decorating a class as a Service Object:
If necessary, create public properties for each property of the Service Object. Decorate the public properties that you want to define as Service Object properties with the [Attributes.Property] Attribute. As part of the attribute, you will need to specify what Service Object Type the Property will be, .e.g Text, YesNo, DateTime and so on.
Decorating Properties as Service Object Properties:
Create public methods for your Service Objects that will accept collections of input Properties, return Properties and the Service Object. Decorate the methods you want to expose with the [Attributes.Method] Attribute.
Decorating methods as Service Object Methods:
The method is where you will write the code that interacts with the provider and populates the Service Object properties. Remember to return an instance or collection of the Service Object class at the end of the method.
To define static parameters for the method, decorate it similar to the following example, which adds the File parameter.
Example of static parameter for a static service object method:
To retrieve any input properties or parameters passed in by the user, you can just query the Property of the class. K2 will automatically populate the class properties with the values entered by the user when they execute the method.
Reading the input properties and parameters passed in by the user:
Next you will need to override and implement the DescribeSchema() method in the ServiceAssemblyBase base class. This method is called when you register or refresh a Service Instance, and it is used to list the available Service Objects for a Service Broker. Note that you will manually register or refresh a Service Instance to call this method. K2 does not "poll" or otherwise automatically update the list of Service Objects in a Service Broker.
Since this is a described schema Broker, all you need to do in the DescribeSchema() method is add each of your classes that you have decorated with the [Attributes.ServiceObject] attribute in Step 5
Implementing the DescribeSchema() method:
For a Described/Attributed Service Object, it is not necessary to implement the Execute() method. K2 will automatically execute the appropriate Service Object method based on the inputs passed in when the Service Object is executed.
Video | Links | Learn | Support |
No videos found for this article K2 on YouTube
No Additional links found for this article
No self-learning content for this article Try some scenarios...
No relevant support links available for this article
|