Using the web services via HTTP requests
Check out this article and learn how to access a WCF web service method using HTTP requests from a HTML application
The WCF web services can be used programatically (from a C# environment, for example) but can also be accessed using HTTP requests from a HTML application. Take a look below to see how a web service method can be called via HTTP.
Login example
The WCF SecurityService Documentation lists the Login method as follows:
Login(string sessionId, Guid clientId, string userName, string password, bool isDomainUser, int millisecondsTimeOut)
This method follows the WEBfactory i4scada Security Protocol.
Syntax |
|
Description | Tries to perform a user login against server or ActiveDirectory. The login will be done in one single operation. If login fails, an exception will be thrown. |
Parameters |
|
Return Value | A security token which can be used in all subsequent secured operations |
HTTP request for the Login method
Using the above information, the HTTP request can be constructed as follows:
Request URL |
The URL is created using the HTTP endpoint and the method name:
|
Request Method | POST |
Request Payload | { "sessionId": "5c1dea15-2516-4836-a1b0-b7bf6769cf31", "clientId": "94e87366-c0ac-407d-b61a-3a5a4a5eec06", "userName": "webfactory", "password": "webfactory", "isDomainUser": false, "millisecondsTimeOut": 10000 } The same parameters as listed in the method documentation are sent as payload for the POST request. |
Response | { "d": "H4sIAAAAAAAEAAXB22JDMAAA0A/y0NWkeNhD3BOteyS8oaC7FAA==" } The request will return the security token if the log in was successful. This security token can be further used in all security methods. If the login fails, an empty string will be returned. |
LogoutByToken example
After a successful login, any other security related actions, like logging out, can be called using the security token returned by the Login method. The WCF SecurityService Documentation lists the LogoutByToken method as follows:
Syntax |
|
Description | Logs out the currently logged in user using the security token |
Parameters |
|
Return Value | A true or false depending on the success of the logout operation |
HTTP request for the LogoutByToken method
Using the above information, the HTTP request can be constructed as follows:
Request URL |
The URL is created using the HTTP endpoint and the method name:
|
Request Method | POST |
Request Payload | { "securityToken": "H4sIAAAAAAAEAAXB22JDMAAA0A/y0NWkeNhD3BOteyS8oaC7FAA==", "millisecondsTimeOut": 10000 } The same parameters as listed in the method documentation are sent as payload for the POST request. The securityToken is returned by the Login method. |
Response | { "d": true } The request will return a boolean value, as described in the method documentation. |
IsUserLoggedIn example
Another useful request could be for checking if a user is logged in. The WCF SecurityService Documentation lists the IsUserLoggedIn method as follows:
Syntax |
|
Description | Checks if the current user is still logged in |
Parameters |
|
Return Value | True if the current user (identified by the security token) is still logged in; otherwise, false. |
HTTP request for the IsUserLoggedIn method
Using the above information, the HTTP request can be constructed as follows:
Request URL |
The URL is created using the HTTP endpoint and the method name:
|
Request Method | POST |
Request Payload | { "securityToken": "H4sIAAAAAAAEAAXB22JDMAAA0A/y0NWkeNhD3BOteyS8oaC7FAA==", "millisecondsTimeOut": 10000 } The same parameters as listed in the method documentation are sent as payload for the POST request. The securityToken is returned by the Login method. |
Response | { "d": true } The request will return a boolean value, as described in the method documentation. |