TN WW100 Wonderware Integration with Web Services
As the capabilities of manufacturing systems grow, integration between these systems is inevitable. When designing an integration strategy it is important to remember the importance of developing a standard for all systems to follow. A web service is a program that handles communication and data exchange between two software applications. Typical use cases of web services include downloading Work Order Information, Bill Of Material, Manufacturing Resource Planning and other information from an ERP system, or posting production / consumption information to an ERP System from a local plant's MES application. When a web service is developed it typically will define the following:
- How one system can communicate with another system
- When data or an operation is requested, what parameters need to be defined
- When data is returned to a client after a request, what format is it returned in
- When errors occur, what type of messages are sent to the client application
A high level view of web services is pictured below. The figure displays multiple plants requesting and transmitting manufacturing related data to and from Enterprise Level Manufacturing Systems. So that each plant doesn’t request this information differently a web service can be used to standardize the data exchange between multiple plants and the Enterprise Manufacturing Systems.
This how-to guide will walk you through creating a simple web-service in visual studio and calling it from Wonderware Application Server.
Applies to Software
Wonderware Application Server
Applies to Version
Applies to System/Module
Before you Begin
This how-to article assumes basic understanding of Wonderware Application Server, Visual Studio, Internet Information Services and Programming / Scripting. While there are many tools for developing a Web Services, this example will use Visual Studio C# .Net. The client system in this example is Wonderware Application Server.
Visual Studio 2012
Internet Information Services 7.0
.Net Framework 3.5 Service Pack 1
Developing the Web Service
A Web Service is an application that is exposed via the Internet / Intranet as a providing system to other client applications and systems. A Web Service will have multiple operations, known as Web Methods associated with them. The section will walk you through developing a simple web service, that contains one web method.
Open visual studio and choose File -- New -- WebSite
Change the target .Net Framework to .Net Framework 3.5, choose the ASP.NET Empty WebSite click the browse button to choose a web location
Choose the Default Web Site for IIS and click the "Create New Web Application" icon. Name the Web Application "SimpleWebService". After choosing the location click open.
A blank website now exists within Visual Studio. Right click on the website and choose Add -- Web Service
Name the Web Service ManufacturingData
In the ManufacturingData.cs create the following Class and WebMethod
Here is the code for the Class and WebMethod:
public class WorkOrder
public string WO;
public WorkOrder getWorkOrder(string MachineName)
WorkOrder rtnWorkOrder = new WorkOrder();
rtnWorkOrder.WO = "WO123";
rtnWorkOrder.WO = "WO456";
rtnWorkOrder.WO = "WO789";
rtnWorkOrder.WO = "Invalid Machine";
catch (Exception ex)
rtnWorkOrder.WO = "Error in getWorkOrder " + ex.Message.ToString();
In the Web.Config file find the system.Web section and add the following entries. This is required to Get and Post data from the web service.
Here is the XML code for the web.Config entry
Perform a build on the solution.
Note that this code doesn't interact with another system for the sake of keeping this article simple. In a real environment the code within the Web Service would handle the communication to the system providing and storing information. This could an ERP system, SQL Server Database, etc... The benefit of the web service is that it can be used across multiple plants and software applications, so long as the client software can communicate with the web service. Now when the providing system needs to be changed, for example a database table change, it can be updated in the web method and client applications will not see the impact after the changes have taken place. Also access and transactions within the providing system can be controlled.
Testing the Web Service
Since the web service was built within IIS we can test it using Internet Explorer. Open Internet Information Services and locate the SimpleWebService application. Right click and switch to Content View.
The ManufacturingData.asmx file will be listed. This is the file generated from the Visual Studio project. Right click on it and choose the option to browse.
The Web Service will be displayed within Internet Explorer. The list of operations within the Web Service will also be listed.
The getWorkOrder web method should be listed. Click on the getWorkOrder link. To test the Web Method type in a parameter for the MachineName and click Invoke.
The return from the WebMethod should be displayed.
Calling the Web Service from Wonderware Application Server
Create a derived template from the $UserDefined object and name it $WebServiceExample. Within this object create the following three User Defined Attributes:
Data Type: String
Default Value: http://<YourServerName>/SimpleWebService/ManufacturingData.asmx/
**Add your Server Name into string
Lock the default value
Data Type: Boolean
Default Value: None
Leave default value unlocked
Data Type: String
Default Value: None
Leave default value unlocked
Create a script to call the Web Service. This script will call the Web Service by loading into an XML Document. It will then parse the XML Document to retrieve the Work Order values returned from the Web Service.
Script Name: scGetWorkOrder
Trigger type: DataChange
'Create new XML Document
dim objDoc as System.Xml.XmlDocument;
objDoc = new System.Xml.XmlDocument;
'Load XML document from getWorkOrder Web Method
'Pass object name as Machine Name
objDoc.Load(Me.cfgWebServiceURL + "getWorkOrder?MachineName=" + me.Tagname);
'Set WorkOrder attribute from WebMethod result
Me.WorkOrder = objDoc.GetElementsByTagName("WO").Item(0).InnerText.ToString();
Save, Close and Check-In the $WebServiceExample object. Create an Instance of the $WebServiceExample object and name it Machine1. Deploy the Machine1 object.
View the Machine1 object in Object Viewer, viewing the WorkOrder attribute of the Machine1 object will display WO123, returned from the web service.
To further test the Web Service, create other instances of the $WebServiceExmaple called Machine2 and Machine3. These objects will return a Work Order based on the Web Services's Web Method. To change the return value of the WebService call, the getWorkOrder web method can be edited.
The benefits of Web Services are that systems that are being tested can easily switch between Testing, QA and Production environments just by changing the URL of the Web Method. Web Services can be firewall friendly applications, and offer advanced security features when hosted within Internet Information Services. The most beneficial aspect of implementing Web Services is the control of access and information exchange between the systems.