Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

We provide an API via Web-Service that can read and write tag values. To access the tags, a Log In is required for the project users. You can directly access this API through the HTTP (REST API) or by using .NET code after the WebServer (Microsoft Internet Information Service (IIS) or TWebServer) is running properly.

This page presents information about how to use WebAccess REST API.

On this page:

Table of Contents
maxLevel3
stylenone


API via Web-Service

We provide an API via Web-Service that can read and write tag values. To access the tags, a Log In is required for the project users. You can directly access this API through the HTTP (REST API) or by using .NET code after the WebServer (Microsoft Internet Information Service (IIS) or TWebServer) is running properly.


Installation Procedure

For the Web-Service to be available, you must either use our documentation to configure the IIS or by running the TWebServer.

If you do not have the documentation “FactoryStudio and IIS”, please contact our support team. After the WebServer is configured, the Web-Service should be available to the user.

It is important to check the port in which the WebServer is running. If the WebServer is not using the default port (80), you should include that information on every URL described through the document using the syntax: <IPAddress><PortNumber>.


Contract Methods - Using Rest API

The Web-Server URLs have the following URL syntax "http://<IPAddress>/<ProductVersion>/WebAccessService.svc/<ContractMethod>" where the contract methods are described below.

GetVersion() 

Gets the service version.

Syntax:

  1. Method: GET
  2. URL Example: http://localhost/fs-8.1/WebAccessService.svc/GetVersion
  3. Response Example:
Code Block
{"GetVersionResult":2}


Login(string userName, string password)

Logs in project user. Parameters:

  • userName: User No case.
  • password: Password. Case

Syntax:

  1. Method: GET
  2. URL Example: http://localhost/fs-8.1/WebAccessService.svc/Login?userName=guest password=test.
  3. Response Example:
Code Block
{
"LoginResult":
	{
	"Handle": 2,
	"Status": ""
}
}
Returns the connection handle (whether >= 0) or error code (whether < 0).


Logout(int handle)

Logs out project user. Parameters:

  • handle: Connection. This value was returned by Login method.

Syntax:

  1. Method: GET
  2. URL Example: http://localhost/fs-8.1/WebAccessService.svc/Logout?handle=1.
  3. Response Example:
Code Block
{
"LogoutResult": 0
}
0: OK, 1: Invalid connection handle.


ReadObject(int handle, string objectName)

Reads value from specified object. Parameters:

  • handle: Connection. This value was returned by Login method.
  • objectName: Object (Tag) Name.

Syntax:

  1. Method: GET
  2. URL Example: http://localhost/fs-8.1/WebAccessService.svc/ReadObject?handle=1&objectName=tagExample.
  3. Response Example:
Code Block
{
"ReadObjectResult":
	{
	"ObjectName": "tagExample",
	"Quality": 64,
	"UtcTimeStamp": "11/29/2019 17:33:47",
	"Value": "0"
}
}
Returns Value of the object.


ReadObjects(int handle, IList<string> objectNames)

Read value from a list of objects. Parameters:

  • handle: Connection. This value was returned by Login method.
  • objectNames: Objects (Tags) Name.

Syntax:

  1. Method: POST
  2. URL Example: http://localhost/fs-8.1/WebAccessService.svc/ReadObjects .
  3. Body Example:
Code Block
{
"handle" : 1,
"objectNames" :["tagExample1", "tagExample2"]}

4. Response Example:

Code Block
{
"ReadObjectResult":
	{
	"ObjectName": "tagExample1",
	"Quality": 192,
	"UtcTimeStamp": "02/12/2021 11:13:38",
	"Value": "20"
},
{
 	"ObjectName": "tagExample2",
	"Quality": 192,
	"UtcTimeStamp": "02/12/2021 11:13:36",
	"Value": "10" 
}
}
Returns Value of the objects.


WriteObject(int handle, ObjectItem item, bool force)

Write value to specified object. Parameters:

  • handle: Connection. This value was returned by Login method.
  • item: Object (Tag) Name.
  • force: Flag to force value.

Syntax:

  1. Method: POST
  2. URL Example: http://localhost/fs-8.1/WebAccessService.svc/WriteObject.
  3. Body Example:
Code Block
{
	"handle" : 1,
	"item" : {
   	"ObjectName": "tagExample2",
	"Quality": 192,
	"UtcTimeStamp": "02/12/2021 11:13:36",
	"Value": "2"  
	}
	"force": false}

4. Response Example:

Code Block
"WriteObjectResult": true
Returns Flag indicating success or fail.


WriteObjects(int handle, IList<ObjectItem> items, bool force)

Write value to specified object. Parameters:

  • handle: Connection. This value was returned by Login method.
  • items: Object (Tag) Names.
  • force: Flag to force value.

Syntax:

  1. Method: POST
  2. URL Example: http://localhost/fs-8.1/WebAccessService.svc/WriteObjects.
Code Block
{
	"handle" : 1,
	"itens" : 
	[{
   	"ObjectName": "tagExample1",
	"Quality": 192,
	"UtcTimeStamp": "02/12/2021 11:13:36",
	"Value": "2"  
	},
	{
   	"ObjectName": "tagExample2",
	"Quality": 192,
	"UtcTimeStamp": "02/12/2021 11:13:36",
	"Value": "13"  
	}],
	"force": false}

4. Response Example:

Code Block
"WriteObjectsResult": [true, true]
Returns Flag indicating success or fail.



Contract Methods - Using .NET

To use the API via .NET, you must reference the T.WebAccess.Contract.dll, which is available in the installation folder, and add T.WebAccess as ”using” to the project class.

GetVersion()

Gets version of service.

Code Block
/// <summary>
/// Get version of service
/// </summary>
/// <returns></returns> int GetVersion();

Example:
IContract _channel;
int version = _channel.GetVersion();


Login(string userName, string password)

Logs in project user. 

Method Signature:

Code Block
/// <summary>
/// Log in user
/// </summary>
/// <param name="project">Project name. No case sensitive</param>
/// <param name="userName">User name. No case sensitive</param>
/// <param name="password">Password. Case sensitive</param>
/// <returns>Return connection handle (whether >= 0)
/// or error code (whether < 0) </returns> LoginStatus Login(string userName, string password);

Example:
IContract _channel;
_channel = factory.CreateChannel();
LoginStatus result = _channel.Login(userName, userPassword);


Logout(int handle)

Logs out project user. 

Method Signature:

Code Block
/// <summary>
/// Log out user
/// </summary> /// <param name="handle">Connection handle.
/// This value was returned by Login method</param>
/// <returns>0: OK, 1: Invalid connection handle</returns> int Logout(int handle);

Example:
IContract _channel; _channel = factory.CreateChannel(); int ret = _channel.Logout(_handle);


ReadObject(int handle, string objectName)

Reads value from specified object. 

Method Signature:

Code Block
/// <summary>
/// Read value from specified object
/// </summary> /// <param name="handle">Connection handle.
/// This value was returned by Login method</param>
/// <param name="objectName">Object name</param>
/// <returns>Value of the object</returns> ObjectItem ReadObject(int handle, string objectName);

Example:
IContract _channel;
_channel = factory.CreateChannel();
string value = _channel.ReadObject(handle, objectName.Text).Value;


WriteObject(int handle, ObjectItem item , bool force)

Writes value to specified object. 

Method Signature:

Code Block
/// <summary>
/// Write value to specified object
/// </summary>
/// <param name="handle">Connection handle This value was returned by Login method</param>
/// <param name="item">Object</param>
/// <param name="force"Flag to force value</param>
/// <returns>Flag indicating success or fail</returns> bool WriteObject(int handle, ObjectItem item, bool force);

Example:
IContract _channel;
_channel = factory.CreateChannel();
bool ret = _channel.WriteObject(_handle, new ObjectItem(objectName, objectValue, 192, DateTime.UtcNow.ToString(CultureInfo.InvariantCulture)), false);



In this section:

Page Tree
root@parent
spacesV10