Top | Previous | Next |
Overview & Simple Arguments |
Web Services Overview Web services are software solutions that allow for interacting with machines residing on a network. In short, web services are nothing more than web pages for machines. They provide a standard way for a third party to request and receive data from a piece of hardware on the network without having to know anything about how that machine works. Other programs interact with the service through an interface defined by a WSDL (Web Services Description Language) file. This WSDL describes how to talk with the device and what should be expected back in response. Messages to and from the web service are formatted XML and while you need very little knowledge of XML to use the SUDS library, many times a web service will return a formatted XML string that you will have to parse through manually in order to make the data presentable.
The SUDS Library The SUDS library is soap-based web services client developed for python. It is extremely simple to use and practically eliminates the need for the user to understand or even view the WSDL of a web service. The SUDS library interprets the WSDL file for you and through couple simple function calls allows you to get a list of the available methods provided to you by the web service. You can then invoke these methods in Ignition through event scripting to send and receive data in your projects. You will have to familiarize yourself with the SUDS library in order to make use of it. The SUDS documentation and the PyDocs are a good place to start.
A Simple Example If you read through the SUDS documentation you'll see that the Client object is the primary interface for most users. It is extremely simple using this object and a few print statements to view a list of available methods provided by the web service you are connecting to. This example will illustrate how to make an initial connect to a web service, print out the list of available methods, and then call one of these methods and display the resulting value in a label on an Ignition window at the push of a button. The below example uses a public web service and is available for anyone to test against.
First, we can use the script playground to test out some scripting calls and see the output. The below example shows how to get a reference to a client object. By printing this client object to the console we get an output of all the available methods, types and other information about the web service as defined in the WSDL file.
This WSDL defines two functions: CelsiusToFahrenheit(string Celsius) and FahrenheitToCelsius(string Fahrenheit). These are the functions that this web service makes available to you. Don't worry about the fact that the methods are listed twice. This is just because the WSDL has two definitions of the functions that are formatted for different SOAP version standards. To call these functions in Ignition scripting you have to make use of the "service" member of the client object.
To make a simple conversion window in an Ignition project you can add two buttons, a numeric textbox, and a lable to a window. Then on the button to be used to calculate a Fahrenheit to Celsius calculation you would place something like the following:
Then on the second button do the opposite.
With your scripts in place your window should now function as a simple temperature conversion tool!
This example is extremely simple and rather straight forward. The main steps to remember when attempting to use the SUDS library in scripting are as follows:
from suds.client import Client
client = Client("url_to_your_wsdl")
client.service.MyMethod(myArgument)
|