SmartObject REST Services

This content applies to legacy components (such as K2 Studio and K2 for Visual Studio), legacy assemblies and APIs, legacy services or other legacy functionality. These legacy items may not be available, supported, or behave as described, in future updates or versions of K2. Please see the legacy component and API support policies for more information about support for these components

K2 can expose SmartObjects as RESTful services that expose SmartObject methods as REST service endpoints. This API is mostly used when developers want to interact with SmartObjects in a technology other than .NET (for example, jQuery) or do not wish to add a reference to a service to their .NET project.

The main difference between the WCF SmartObjects services and the RESTful SmartObject services is that the RESTful services expose each method of the selected SmartObjects as a separate endpoint. This means that developers will access the methods by submitting GET requests to a specific URI. The URI would point to a specific method for a specific SmartObject.

The RESTful services support XML, ATOM and JSON output formats, and you can specify which format you want returned with a query string options appended to the service endpoint.

The SmartObject REST are configured in conjunction with the WCF services by editing the K2HostServer.exe.config file, so when exposing a SmartObject as an endpoint it will be exposed on both WCF and REST. You cannot independently specify which SmartObjects will be exposed on REST and which on WCF. The only independent setting is the <Binding> which determines the security that is used for the WCF and REST services

The image below illustrates how a REST service endpoint is constructed

The Service Root URI is defined by the <smoServices> section of the K2HostServer.exe.config file. The Service path is defined by the SmartObject’s location in the category system (or by the Alias value specified in the K2HostServer.exe.config file), and each Method for the SmartObject is appended to create separate endpoints for each SmartObject method.

All the available endpoints for a K2 environment (WCF and REST) are viewable in the endpoints.xml file. The exact address depends on the configuration of the smoServices section of the K2HostServer.exe.config file, but it usually looks something like this:
http(s)://[Server]:[Port]/SmartObjectServices/endpoints/endpoints.xml

For code samples demonstrating interact with the SmartObjects REST Services, see the topic SmartObject REST Services Samples. For more information on the configuration of this service, please see the topic SmartObject REST Services Reference

Troubleshooting

Issue:

You get the error: Object 'X' has been disconnected or does not exist at the server.

Details:

A timeout occurs when executing endpoints SmartObjects, such as those based on WCF, Web Services, and assemblies.

Endpoint SmartObjects create their own appdomains that use an appdomain communcation channel when you execute a SmartObject method. When the lifetime of the channel expires, you get a timeout error. You can change a setting in the K2HostServer.config file to adjust the time the channel stays open waiting for a response, in minutes.

Resolution:

  1. Stop the K2 Server
  2. Add the attribute appdomainproxytimeout to <sourcecode.smartobjects.runtime node of the <install drive>:\Program Files\K2\Host Server\Bin\K2HostServer.exe.config file

  3. And specify your desired timeout in minutes.

  4. Start the K2 server.