Skip to main content
InSource Solutions

TN WW100 Wonderware Integration with Web Services

 

 

insource_logo_large.jpg HOWTOSMALL.jpg
HOW TO

Description

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:

 

  1. How one system can communicate with another system
  2. When data or an operation is requested, what parameters need to be defined
  3. When data is returned to a client after a request, what format is it returned in
  4. 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. 

 

WebServiceOverview.PNG

This how-to guide will walk you through creating a simple web-service in visual studio and calling it from Wonderware Application Server. 

 

Author

Michael Walker

Publish Date  

Applies to Software

Wonderware Application Server

Applies to Version

 

Applies to System/Module

MES, Scripting

Article Version

zz

Before you Begin

Edit section

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.  

Pre-Requisites

 
The following software needs to be installed to follow the article
 
Wonderware Application Server (2014 is used in the example, but any version should work)

Visual Studio 2012

Internet Information Services 7.0

.Net Framework 3.5 Service Pack 1

Detailed Steps

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

vsCreateWebSite.PNG

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

vsBrowseWebsite.PNG

 

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.

vsCreateWebApplication.PNG

 

A blank website now exists within Visual Studio.  Right click on the website and choose Add -- Web Service

vsAddWebService.PNG

 

Name the Web Service ManufacturingData

vsNameWebService.PNG

 

In the ManufacturingData.cs create the following Class and WebMethod

vsWebMethodCode.PNG

 

 

Here is the code for the Class and WebMethod:

 

    public class WorkOrder
    {
        public string WO;
    }

 

    [WebMethod]    
    public WorkOrder getWorkOrder(string MachineName)

    {
        WorkOrder rtnWorkOrder = new WorkOrder();
        

        try
        {
            switch (MachineName)
            {
                case "Machine1":
                    {
                        rtnWorkOrder.WO = "WO123";
                        return rtnWorkOrder;
                    }
                case "Machine2":
                    {
                        rtnWorkOrder.WO = "WO456";
                        return rtnWorkOrder;
                    }
                case "Machine3":
                    {
                        rtnWorkOrder.WO = "WO789";
                        return rtnWorkOrder;
                    }
                default:
                        rtnWorkOrder.WO = "Invalid Machine";
                        return rtnWorkOrder;
            }
        }
        catch (Exception ex)
        {
            rtnWorkOrder.WO = "Error in getWorkOrder " + ex.Message.ToString();
            return rtnWorkOrder;
        }
    }

 

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. 

vsWebConfigEdit.PNG

Here is the XML code for the web.Config entry

      <webServices>
        <protocols>
          <add name="HttpGet"/>
          <add name="HttpPost"/>
        </protocols>
      </webServices>

 

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. 

issShowContent.PNG

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. 

issBrowseWebService.PNG

The Web Service will be displayed within Internet Explorer.  The list of operations within the Web Service will also be listed. 

issIEMethod.PNG

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. 

 

issIEParam.PNG

The return from the WebMethod should be displayed. 

issIEWebMethodReturn.PNG

 

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:

Name: cfgWebServiceURL

Data Type: String

Default Value: http://<YourServerName>/SimpleWebService/ManufacturingData.asmx/​

**Add your Server Name into string

Lock the default value

 

iasUDAURL.PNG

 

 

Name: GetWorkOrder

Data Type: Boolean

Default Value: None

Leave default value unlocked

 

iasUDAGetWorkOrder.PNG

 

 

Name: WorkOrder

Data Type: String

Default Value: None

Leave default value unlocked

 

iasUDAWorkOrder.PNG

 

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

Expression: me.GetWorkOrder

Trigger type: DataChange

Script:

 

'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();

 

iasScriptGetWorkOrder.PNG

 

Save, Close and Check-In the $WebServiceExample object. Create an Instance of the $WebServiceExample object and name it Machine1. Deploy the Machine1 object. 

 

iasDeployInstance.PNG

 

View the Machine1 object in Object Viewer, viewing the WorkOrder attribute of the Machine1 object will display WO123, returned from the web service. 

 

iasObjectViewer.PNG

 

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. 

Conclusion

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.

 

M.J.W.