Requesting Values via the Web Service
This example uses a PHP web page to interact with the VTScada web service.
The point of this example is to show that any program that can access web services can now interact with VTScada. You could call the web service from another VTScada application, from a CGI script in a web page as shown here, or from your own web-enabled application.
While the following code does work, it should not be taken as representing a fully developed application. PHP was selected for this example as it is freely available and relatively easy to use, but problems that can be traced to the PHP configuration have been reported.
Success when using web services will require that you understand the SOAP protocol support in your chosen client.
** Trihedral Engineering provides no support for programs other than VTScada. **
The process of making the call to VTScada's web services is to send a SOAP-encoded message, calling the operations that were exposed with the WSDL file. Depending on your application, you may or may not need to include a header with the SOAP-encoded message. If so, the header would look something like this:
POST /TagQueryServicesRealm/SOAP/ HTTP/1.1 Host: localhost Content-Type: text/xml; charset="utf-8" Content-Length: 343 SOAPAction: "http://localhost/GetTagValue"
In the case of this PHP example(*), this header is not required as the PHP SOAP client object takes care of it automatically.
<html><head><title>VTScada Web Services Tester</title></head> <body bgcolor="#ffffff"> <?php echo "<h2>VTScada Web Services Tester</h2>"; // create an instance of PHP's SOAP client object // the client should not need a local copy of the .WSDL. It can pull it from the server $client = @new SoapClient("http://localhost/QueryServicesRealm/WSDL"); $params = array('TagName'=>'AI20_1'); try { $result = $client->GetTagValue($params); $tagvalue = $result->TagValue; echo "The value of AI20_1 is ".$tagvalue; } catch (SoapFault $exception) { echo $exception; } ?> </body> </html>
Full tag names are supported. For example, to access a tag from the Completed Tutorial Example, use:
$params = array('TagName'=>'Local TCP Port\PLCSim\Pump 1\Motor Speed');
If you are attempting to follow this example and errors are returned, you are advised to do a web search using the text of those error messages. A scan of online forums related to making SOAP calls from PHP will reveal a number of common problems and solutions. Messages in your PHP error log file may also be useful for this search. In particular, be careful to configure VTScada and Apache with differing port numbers, and if VTScada is using a number other than 80, adjust the addressing in the client to match.
If security is enabled in your VTScada application, then ensure that your account has the Thin Client Access privilege and modify the SoapClient call as follows:
$client = @new SoapClient("http://localhost/QueryServicesRealm/WSDL", array('login' => "Your User Name", 'password' => "Your Password"));
For the sake of simplicity in the example, no effort is made to protect the user name and password. Keep security in mind as you develop your own client application.