Exposed Operations

The following sections describe security, services, and CORS support.

Structure of the Service Base URL

The Service Base URL, which is set in the Service Hosting tab of the JIA Configuration Screen, defines the URL access to the service of a JIA project. In addition to a base URL, the Service Base URL can contain a namespace and a sessionId. The sessionId is included in the URL if it is used in the Init method of the service.

For example: http://<host:port>/<namespace>/<sessionId>

tog_minusSecurity

This section is relevant to the Windows 7 OS.

When JIA starts, it hosts a WCF service. When running JIA with elevated privileges (such as administrator credentials), there are generally no security issues. However, when running JIA with regular privileges, the following error might display: Your process does not have access rights to this namespace.

To fix this error, run the following command line once as an administrator with your user, proper URL (found in JIA logs) and desired port number:

SecurityFix

When running this command line, take the following issues into consideration:

The user that runs this command must have administrative privileges.

The communication channel (the URL) can be opened up only to a single user (as in the example above) or to one user group per project.

Note: It is strongly recommended to create an Agents group, and to use it in the API. The name of the user group should not contain spaces. For example:
user=<Domain>\<Agents group>
Defining this group enables all the users in the Agents group to execute the automation (not only a single user).

If a user already exists (e.g., http://+:Services in the command line above), delete it, using
netsh http delete urlacl url=http://+:9002/services.

tog_minusServices

Exposed operations are required to allow external communication with JIA. To expose functions, it is necessary to implement the IService interface:

IService Interface

Appropriate attributes should be added to the functions, for example:

[OperationContract]

If exposed operations are meant for WorkSpace, the following attribute should also be added:

[WebInvoke(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]

It is possible to expose more than one Service Contract, but each one should implement the IService interface.

Exposed operations should be marked as virtual methods. This ensures that the underlining code can handle all exceptions thrown while executing the operation, and display these exceptions in the system tray.

tog_minusCORS Support

Browser security protocol prevents a web page from making AJAX requests to another domain. This restriction is called the same-origin policy.

Cross Origin Resource Sharing (CORS) is a W3C standard that allows a server to relax the same-origin policy. Using CORS, a server can explicitly allow some cross-origin requests while rejecting others. The CORS standard can be used in your JIA project to allow other sites to call your web APIs.

To configure service methods to support cross domain calls, in the service.cs file under the interface, add the CorsEnabled tag to each service for which cross domain calls should be supported. For example:

namespace SimpleWeb

{

 

[ServiceContract]

public interface IService

{

 

 

[OperationContract]

[STAOperationBehavior]

[WebGet(UriTemplate = "HelloWorldGet"), CorsEnabled]

string HelloWorldGet();

 

 

[OperationContract]

[STAOperationBehavior]

[WebGet(UriTemplate = "HelloWorldGetMsg/{msg}"), CorsEnabled]

string HelloWorldGetMsg(string msg);

 

[OperationContract]

[STAOperationBehavior]

[WebInvoke(UriTemplate = "HelloWorldPut", Method = "POST"), CorsEnabled]

string HelloWorldPost(Stream content);

 

[OperationContract]

[STAOperationBehavior]

[WebInvoke(UriTemplate = "HelloWorldPutMsg?msg={msg}", Method = "POST"), CorsEnabled]

string HelloWorldPostMsg(string msg, Stream content);

 

 

[OperationContract]

[STAOperationBehavior]

[WebInvoke(UriTemplate = "HelloWorldPut", Method = "PUT"), CorsEnabled]

string HelloWorldPut(Stream content);

 

[OperationContract]

[STAOperationBehavior]

[WebInvoke(UriTemplate = "HelloWorldPutMsg?val={val}", Method = "PUT"), CorsEnabled]

string HelloWorldPutMsg(string val, Stream content);

 

 

}