haggaipp

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Web API, REST API, version 6 #10442
    haggaipp
    Participant

    Hi, Mikhail.
    Can I get data from this url: http://webserver/scada/ClientApiSvc.svc/GetCurCnlDataExt?cnlNums=&viewIDs=&viewID=1

    I use XMLHttpRequest in my JS code. But it always says, user not logged in. When i check the ScadaWeb.log it keeps adding User Information in every request. Can you solve this?

    My Javascript code:

    var xhttp = new XMLHttpRequest();
    
        function main() {
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    // Typical action to be performed when the document is ready:
                    let tmp = JSON.parse(xhttp.responseText);
                    let response = JSON.parse(tmp.d);
                    console.log(response);
                    if (response.Success) {
                        if (response.Data) {
                            getData();
                        } else {
                            console.log("SERVER NOT LOGGED IN");
                            logIn();
                        }
    
                    } else {
                        console.log("[ERROR]: " + response.ErrorMessage);
                    }
                }
            };
            xhttp.open("GET", "http://localhost:8080/scada/ClientApiSvc.svc/CheckLoggedOn", true);
            xhttp.send();
        }
    
        function logIn() {
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    // Typical action to be performed when the document is ready:
                    let tmp = JSON.parse(xhttp.responseText);
                    let response = JSON.parse(tmp.d);
                    console.log(response);
                    if (response.Success) {
                        if (response.Data) {
                            console.log("LOG IN SUCCESSFUL!");
                            // getData();
                            // main();
                        } else {
                            console.log("FAILED TO LOG IN!");
                        }
                    } else {
                        console.log("[ERROR]: " + response.ErrorMessage);
                    }
                }
            };
            xhttp.open("GET",
                "http://localhost:8080/scada/ClientApiSvc.svc/Login?username=admin&password=12345&callback=true", true);
            xhttp.send();
    
        }
    
        function getData() {
            xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    // Typical action to be performed when the document is ready:
                    let tmp = JSON.parse(xhttp.responseText);
                    let response = JSON.parse(tmp.d);
                    console.log(response);
                    if (response.Success) {
                        console.log("FETCH DATA SUCCESSFUL!");
                        console.log(response.Data)
                    } else {
                        console.log("[ERROR]: " + response.ErrorMessage);
                    }
                }
            };
            xhttp.open("GET",
                "http://localhost:8080/scada/ClientApiSvc.svc/GetCurCnlDataExt?cnlNums=&viewIDs=&viewID=2&callback=true",
                true);
            xhttp.send();
        }
    
        getData();

    Scada Web Log:

    2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Request SCADA-Server state
    2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Disconnect from SCADA-Server
    2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Connect to SCADA-Server "localhost"
    2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> User information has been added. IP address: ::1. Session: fgkmemvsn0avgnhrfx1f40sw
    2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Login: admin (Administrator). IP address: ::1
    2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> User information has been updated. IP address: ::1. Session: fgkmemvsn0avgnhrfx1f40sw
    2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Retrieve components from the installed plugins
    2022-08-01 20:08:01 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> User information has been added. IP address: ::1. Session: ul23o4sslwbbznovlxl242w2
    2022-08-01 20:08:01 <DESKTOP-RLH5Q4C><DefaultAppPool><EXC> Error getting extended current data by the filter where channels=, view id=2:
    Scada.ScadaException: User not logged on.
       at Scada.Web.UserMonitor.CheckLoggedOn(UserRights& userRights, Boolean throwOnFail)
       at Scada.Web.ClientApiSvc.GetCurCnlDataExt(String cnlNums, String viewIDs, Int32 viewID)

    Or there is the other way to fetch data from OPC server? I use JS and PHP.

    Thank You!

Viewing 1 post (of 1 total)