Sunteți pe pagina 1din 93

Application for Communication

Visual Basic .NET OPC Client for the XML-DA Interface of the SIMATIC NET OPC Server Extension

Warranty, Liability and Support

Data Exchange via XML-DA

Beitrags-ID: 21402169

Warranty, Liability and Support


We accept no liability for information contained in this document. Any claims against us - based on whatever legal reason - resulting from the use of the examples, information, programs, engineering and performance data etc., described in this document shall be excluded. Such an exclusion shall not apply in the case of mandatory liability, e.g. under the German Product Liability Act (Produkthaftungsgesetz), in case of intent, gross negligence, or injury of life, body or health, guarantee for the quality of a product, fraudulent concealment of a deficiency or breach of a condition which goes to the root of the contract (wesentliche Vertragspflichten). However, claims arising from a breach of a condition which goes to the root of the contract shall be limited to the foreseeable damage which is intrinsic to the contract, unless caused by intent or gross negligence or based on mandatory liability for injury of life, body or health. The above provisions does not imply a change in the burden of proof to your detriment. The Application Examples are not binding and do not claim to be complete regarding the circuits shown, equipping and any eventuality. They do not represent customer-specific solutions. They are only intended to provide support for typical applications. You are responsible for ensuring that the described products are used correctly. These Application Examples do not relieve you of the responsibility in safely and professionally using, installing, operating and servicing equipment. By using this application example you accept that Siemens is not liable for any damages except for those specified in the above liability clause. We reserve the right to make changes to these Application Examples at any time without prior notice. If there are any deviations between the recommendations provided in this application example and other Siemens publications e.g. Catalogs the contents of the other documents have priority. Copyright 2004 Siemens A&D. Any form of duplication or distribution of these application examples or excerpts hereof is prohibited without the expressed consent of Siemens Energy & Automation, Inc. For questions about this document please use the following e-mail address: mailto:csweb@ad.siemens.de

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

2/93

Foreword

Data Exchange via XML-DA

Beitrags-ID: 21402169

Foreword
Objectives of the application Exchanging process data between logic controllers and computers via OPC is a core element of automation technology. The application on hand shows a possible procedure for independently generating individual OPC clients using the programming language Visual Basic .NET by Microsoft. A visualization of a mixed process is hereby realized in Visual Basic .NET. The programming paradigm ".NET by Microsoft is used here. Main contents of this application The following teaching materials are provided with this application:
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Installation and configuration of a web server (in this example the webserver of the internet information services of Windows). This web server is used for accessing the OPC server. User security (authentication and authorization of clients) for accessing the web-server and the OPC XML-DA web service. Demonstration in dealing with web services in .NET, especially the OPC XML-DA web service. Demonstration of the most important OPC XML-DA methods for accessing the process variables (browsing the OPC Server for available process variables, synchronous writing and reading, asynchronous reading, operator control and monitoring) Demonstration of error handling with .NET Generating an OPC client as Windows application as well as ASP.NET web application (for calling a web browser) with similar function range.

Delimitation

This application does not contain a complete description of network safety aspects (encoded communication via SSL, application of firewalls, using VPNs) of the .NET framework, of the OPC specification as well as deeper level ASP.NET mechanisms

Therefore, basic knowledge in the area of object oriented programming is required. Further knowledge in UML (Unified Modelling Language) is an advantage.

V1.0

26.04.05

3/93

Foreword

Data Exchange via XML-DA

Beitrags-ID: 21402169

Structure of the document The documentation of this application is divided into the following main parts: Introduction Extension Demonstration In addition, two setup programs (for application in Windows and ASP.NET respectively), which also contain the source code of the application, as well as the STEP 7 code, are available. This second document, the Extension part, is aimed at persons who want to have a more detailed overview.
Part
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description Provides a general overview of the contents. You will learn about the components used (standard hardware and software components and the specially created software). Discusses the detailed function processes of the involved hardware and software components, the solution structures, and where sensible the concrete implementation of this application. This part is necessary if you want to learn about the interaction of the solution components, for example in order to use them as the basis for own development. This part leads you step by step through the structure, important configuration steps, commissioning and operation of the application.

Introduction Application Description and Function Principles Extension Function Principles in detail and Program Structure

Demonstration Structure, Configuration and Operation of the Application

An additional component available is the S7 program code.


Part Setup Program of the Windows Application Setup Program of the ASP.NET Application S7 program code Description Installs the Windows application on your PC. The source code of the application is available in the program directory. Installs the ASP.NET application on your PC. The source code of the application is available in the program directory. The S7 program code contains the code and a user interface.

V1.0

26.04.05

4/93

Foreword

Data Exchange via XML-DA

Beitrags-ID: 21402169

Reference for Automation and Drives Service & Support This entry originates from the internet application portal of the A&D Service and Support. The following link takes you directly to the download page of this document. http://support.automation.siemens.com/WW/view/en/21402169

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

5/93

Foreword

Data Exchange via XML-DA

Beitrags-ID: 21402169

Table of Contents
Table of Contents ......................................................................................................... 6 Introduction................................................................................................................... 7 1 Document on Hand......................................................................................... 7

Function Principles and Program Structures ............................................................ 8 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4 4.1 4.2 4.3 4.4 5 5.1 5.2 General Function Mechanisms...................................................................... 8 Internet Information Services (IIS) .................................................................... 8 Safety aspects of the Internet Information Services ....................................... 10 Introduction into XML...................................................................................... 16 SOAP protocol ................................................................................................ 17 Web services .................................................................................................. 18 Including a web service in Visual Studio .NET ............................................... 20 Function mechanisms of.NET Framework...................................................... 24 ASP.NET ........................................................................................................ 26 Safety settings of an ASP.NET application..................................................... 31 Function Mechanisms of this Application.................................................. 35 The OPC XML-DA interface ........................................................................... 35 Synchronous and asynchronous methods of the OPC XML-DA interface...... 39 Used objects and methods of the XML-DA interface ...................................... 41 Cyclic reading of process values (subscriptions) ............................................ 42 Data flow model .............................................................................................. 44 Logic data interface between controller and OPC client................................. 45 Managing the OPC items in the OPC client.................................................... 48 Structure of the Windows application ............................................................. 49 Structure of the ASP.NET application............................................................. 52 Explanations on the Example Program ...................................................... 54 Explanation for the simulation program (S7 program) .................................... 54 Saving the configuration data ......................................................................... 55 Windows applications ..................................................................................... 57 ASP.NET application ...................................................................................... 68 Configuration ................................................................................................ 79 Configuration of an OPC Server with STEP 7 ................................................ 79 Configuration of the Internet Information Services ......................................... 84

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Appendix and List of Further Literature ................................................................... 89 6 7 7.1 7.2 Glossary ........................................................................................................ 90 Literature ....................................................................................................... 92 Bibliographic References................................................................................ 92 Internet links ................................................................................................... 92

V1.0

26.04.05

6/93

Introduction Document on Hand


Data Exchange via XML-DA Entry-ID: 21402169

Introduction
1 Document on Hand
This document is the extension of the document "OPC Client for XML-DA interface of the SIMATIC NET OPC Server Introduction". The Introduction part describes the basic application structure and you should be familiar with its contents before reading the Extension part. Supplementary to the Introduction part, the document on hand includes further in-depth information on the application. However, it is not a substitute for a manual.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

7/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Function Principles and Program Structures


Content Discusses the detailed function processes of the involved hardware and software components, the solution structures, and where sensible the concrete implementation of this application.

General Function Mechanisms


the internet information services (IIS) and its safety aspects. You will be provided with a brief introduction into XML, SOAP, web services, .NETFramework as well as ASP.NET.

Here you will find further information on

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Table 2-1

Chap. 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9

Title Internet Information Services (IIS) Safety aspects of the Internet Information Services Introduction into XML SOAP protocol Web services Including a web service in Visual Studio .NET Function mechanisms of.NET Framework ASP.NET Safety settings of an ASP.NET application

Relevance general general general general general general general ASP.NET application ASP.NET application

Page 8 10 16 17 18 20 24 26 31

2.1

Internet Information Services (IIS)

Introduction The internet information services (IIS Internet Information Services) are the services integrated within the Windows operating system in order to publish information via LAN, intranet or the internet. These services enable a relatively simple commissioning and administration of a web server.

V1.0

26.04.05

8/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Functionality of the IIS Depending on the services, the IIS provide the following services depending on the installation. When installing the internet information services, you should only install those services which you actually want to use (see Demonstration part of this application)
Table 2-2

Service WWW service (or www-server) FTP server SMTP service FrontPage 2000 extension Snap-In IIS

Description Web server enables accessing web sites or web services via HTTP protocol. In this application, only the www-server is installed and used. FTP File Transfer Protocol, enables generating FTP sites for transferring files. Mail server service for transferring e-mails. Enables generating and managing Websites with MS FrontPage. IIS management user interface (internet service manger) for the Microsoft Management Console

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Configuration of the IIS The configuration of the IIS occurs via the internet service manager. A description of the required configuration of the IIS occurs in the "Demonstration" part of this application. The internet services manager is called with: Start Settings vices Manager The WWW-service As already mentioned, the www-service enables accessing web sites or web services (see 2.5 Web services) via the HTTP protocol. Most web sites are static html-sites, but increasingly also dynamic ASP, ASPX, PHP or JSP pages. Web services generated with .NET have the extension ASMX. HTTP protocol The HTTP protocol is used for data exchange within computer networks (internet, intranet or local networks) and is based on TCP/IP. It provides certain http request methods which clients can use to request information from servers. The server then returns the desired information to the client. HTTP is a stateless protocol, i.e. no fixed connections are established between a client and a server (as opposed to a configured S7 connection). This causes the information from former client requests being lost. This also affects the application of the OPC XML-DA interface, which in return is based on SOAP and HTTP (see 3.1 The OPC XML-DA interface). Control Panel Administrative Tools Internet Ser-

V1.0

26.04.05

9/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Standard website and virtual directories The data which the www-service provides on a client server, is available on the standard website. The standard website contains so-called virtual directories. These virtual directories represent a connection with a real directory on the server (or a network release or to an URL which is not discussed further within the framework of this application). The client gains access to certain areas (directories or files) on the server. Structure of the standard website The following figure shows the structure of the standard website (Default Web Site) in the internet service manager. The illustrated structure tree is the standard setup after installation of .NET Framework and IIS. The right pane, under Path, contains the actual positions of the virtual directories ("Name") on the server.
Figure 2-1
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Access to a web server The access to the web server of a PC via the intranet or the internet occurs from a web client (e.g. a web browser) via the URL (see Glossary) of the PC, as well as the name of the virtual directory and the file to be accessed. This can be set up in various ways: http://[Computer name ]/[Virtual directory]/[File name] http://[IP-address ]/[Virtual directory]/[File name] http://[Your domain]/[Virtual directory]/[File name]

2.2

Safety aspects of the Internet Information Services

General information When using the IIS as web server on the internet, but also the intranet or a local network, you as the commissioning staff or administrator and user must place particular emphasis on network safety.

V1.0

26.04.05

10/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

The mechanisms described below refer mainly to the application safety (authentication and authorization of the application, see Glossary). The wide ranging topic of network safety (safe communication via SSL, Firewall, IPSec, ...) will not be discussed within the framework of this application. Please refer to \10\. Overview The following figure illustrates the safety aspects considered below. The mechanisms in bold print were realized in the application on hand. The web server authentication and authorization (left box in the picture) are explained in this chapter. The ASP.NET or web service authentication and authorization (right box) are discussed in chapter 3.1 The OPC XML-DA interface
Table 2-2
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

11/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Web server authentication Enabling web server access to only one authorized circle of users, requires each user/client to identify himself to the server. The identification occurs mainly via specifying a user name and a respective password. The Client thereby logs in at the Windows user account which exists on the server. Further authorizations are then defined via this user account. The following mechanisms are available for identification of a client on the IIS web server. Please refer to \4\.
Table 2-3

Mechanism Anonymous access Safety: none


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description The access of a client to the web server occurs with the user name "IUSR_Computername" and does not require specifying a user name or password. The user "IUSR_Computername" is assigned to the group "Guests". For this application, the anonymous access is deactivated, so that each client must identify himself at the server. It is a widely used option for identifying users. This method is based on the http-specification (from version 1.1) and is supported by all browsers. Warning For this method, the unencrypted password is transferred via the network (as BASE64 code) and can be viewed by a third party! Therefore, this method should only be applied if a safe connection exists between client and server (e.g. a telephone (dialup) connection or a connection with SSL encryption). The digest authentication provides the same features as the basic authentication. However, the password transfer is encoded here. This method is described in the HTTP 1.1 standard. Due to the fact, that this authentication method is only available with the Windows 2000 server, it is not used in this application. This authentication method also enables encrypted transfer of the login information from the client to the server. The encryption methods used are hash encryption or the Kerboros standard. This authentication method can be used with all standard browsers and is also used in this application. The disadvantage here is that the connection between the client and the server must not occur via a Proxy. This makes the integrated Windows authentication favorable for an intranet environment where the server and all clients are located within the same domain. In this method, the client identifies himself to the server with a digitally signed certificate. This certificate is issued by a credible certification service (e.g. http://www.verisign.com/). For authentication of the client the web server uses SSL/TLS. Due to the fact that issuing a client certificate is not that simple, as well as the integrated Windows authentication being sufficient for this application, this method is not used here.

Basic authentication Safety: low

Digest authentication Safety: high

Integrated Windows authentication Safety: high

Client certification Safety: high

V1.0

26.04.05

12/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Generating the authentication method The authentication methods of the IIS web server are set via the internet services manager. Thereby, the method can be defined globally for the access to the entire web server, or for a certain virtual directory, or a certain file. Please refer to 5.2 Configuration of the Internet Information Services. Web server authorization After the client has authenticated/identified himself at the server, the client is given certain access permissions by the server. These permissions regulate access to the data of the web server. The ISS web-server provides different options of granting these access permissions, which are explained in the following sections. Web permission
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Web permissions are defined directly via the internet services manager (see 5.2 Configuration of the Internet Information Services). Thereby, the permissions can be defined globally for the access to the entire web server, or for a certain virtual directory, or a certain file. The granted permissions apply equally to all clients at the server (as opposed to NTFS permissions). The following permissions can be granted:
Table 2-4

Permission Read Write Script access

Description Clients can read directories or file contents as well as their properties. Activated for this application. Clients can change directories or file contents as well as their properties. Deactivated for this application. (Only available if read or write permissions have been granted) Enables the user to access the source code scripts on the server (e.g. ASP scripts). The script access has been deactivated for this application. Warning When activating script access, it is possible that the client has the option of viewing confidential information, such as user name and password, in scripts of an ASP application. The client may also be able to change the source code on the server, which considerably restricts security and performance of the server. The client can have a list of files and sub-directories displayed in this virtual directory. Deactivated for this application.

Search directory

V1.0

26.04.05

13/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

User settings An IIS application (e.g an ASP.NET application or a web service) is first created as a virtual directory with the internet services manager. This contains one or several files executable in a web browser (e.g. *.asp, *.aspx, *.asmx). This application also includes all sub-directories and files of the virtual directory. This virtual directory must be turned into an application (see 5.2 Configuration of the Internet Information Services). The following settings for an IIS application can then be made in the internet services manager.
Table 2-5

Setting Execution permissions None Scripts only


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description No scripts must be executed (e.g. ASP.NET applications). Only scripts must be executed on the server. This setting is used in this application as well as for the OPC XML-DA web service, as well as for the ASP.NET application. Scripts and executable files may be executed on the server.

Scripts and executable files Low

Application protection The application runs in the IIS process. In case of a crash caused by a program error, the entire web server will also fail and must be rebooted manually. All IIS applications run in a separate process. During a program error within an application all parallel running IIS applications are terminated, however, the web server is not affected. This setting is used in this application as well as for the OPC XML-DA web service, as well as for the ASP.NET application. Each IIS application runs in a separate process. A failure of an IIS application has no effect on other IIS applications or the web server. For many (>10) parallel running IIS applications, however, this setting reduces the performance.

Medium

High

NTFS permissions As opposed to the web permissions of the IIS, the NTFS permissions are granted on the operating system level. On NTFS file systems (for Windows operating systems from Windows NT and later versions) different, individual user access permissions can be provided for each file and each directory. The most important ones are read, write and execution permission. These permissions apply to all applications (i.e. also for IIS or ASP.NET), which access these files or directories under a certain user. The permissions can be granted individually for single users or for user groups. The user and user groups are created and managed in the Windows user administration.

V1.0

26.04.05

14/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Granting NTFS permissions NTFS permissions for certain files or directories are granted in the Windows Explorer via the Properties dialog of the respective file or directory (in the "Security settings" tab).
Note

If web permissions have been granted at the same time as NTFS permissions, the permissions denying access always have priority over the permissions allowing access.

Restrictions for IP addresses This method enables allowing or denying access to the website, directory or file for certain users, computers, several computers, or domains. As this function is only available with the operating system Windows 2000 Server, it is not used in this application.
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

IISLockdown The IISLockdown tool enables automating large parts of the securing process for your web server. You can select a specific server type, which closely matches your web server, and then the most important security settings for your web server are made automatically. This includes: Deactivating not required IIS services (e.g. FTP, e-mail etc.) Executing not required or preventing problematic scripts (e.g. .idq, .shtml, .idc, .printer etc.) Removing not required virtual directories on the web server (IIS Samples, MSADC, IISHelp, Scripts, IISAdmin) Deactivating the anonymous access to the web server Deactivating the WebDAV support (service for editing files on the server and clients) Creating the user group "Web Applications" with restricted access permissions on the PC. Restricting access permission (executing and writing) for the user group "Web Anonymous Users" (anonymous internet access) and "Web Applications" (ASP.NET applications) to various system files and programs (via NTFS permissions) Installation of the URLScan ISAPI filter

V1.0

26.04.05

15/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

URLScan URLScan is an ISAPI (Internet Server Application Programming Interface, see Glossary) filter, which enables the administrator of the IIS (i.e. you) to define, which http requests will be processed by the web server. Depending on the selected web server configuration in the IISLockdown tool, URLScan is automatically configured so that only those http requests absolutely necessary for this configuration are processed.

2.3

Introduction into XML


The following chapter explains the basics of XML, on which web services are based.

The basis for web services: XML


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

XML (Extensible Markup Language) is a standard for structured display of data. In XML files, data is stored in plain text so it can be read by humans and machines alike. This has the advantage, that XML-files can be processed on any systems with any (text processing) programs. XML enables adding various meta information (additional information) to the contained data. Further information on XML is available under the link \6\. Example of an XML file The following example of an XML-file shows all typical signs of XML. It gives a concrete description of a fictitious box with its contents.
Figure 2-3

V1.0

26.04.05

16/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Structure of an XML file The XML-file structure corresponds to a hierarchical tree structure. The following table describes the XML elements.
Table 2-6

Element XML Declaration Element

Description Contains information on the XML file on hand. <?xml version="1.0"> means, that this XML-file corresponds to the XML specification version 1.0. Made up of a start tag <Elementname> and an end tag </Elementname>. The content of the element is located between both tags. Elements without content manage with one tag: <Elementname /> Represent the meta information of an element. They are defined in the start tag of an element: <Elementname Attributname="Attribute value"> Provide a better understanding of the XML document and do not contain specific data: <!-- Comment -->

Attributes

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Comments

2.4

SOAP protocol

Introduction The SOAP-protocol is used for data exchange between computer systems (in this application between the client and the web service). The data of a SOAP message is displayed as text in XML format. This data can be transferred with any transport protocols. The most commonly used transport protocol, which is also used in this application, is HTTP. HTTP can be simply administrated and protected by means of a firewall. Structure of a SOAP message A SOAP message is always divided into two sections:
Table 2-7

Section Head Body

Description Optional. Contains the meta information of the message, e.g. via routing, the encoding, or a particular transaction. Contains the actual message data. This data corresponds to a certain XML scheme.

V1.0

26.04.05

17/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Communication via the SOAP protocol The communication via SOAP is always divided into two steps:
Table 2-8

No. 1 2

Step SOAP Request SOAP Response

Description The client sends a request (as XML telegram) to the server, e.g. to perform a particular function. After processing the request, the server returns the result to the client in an XML telegram, e.g. the result of the called function.

Communication via the SOAP protocol The following figure illustrates once more the sequence of a SOAP communication.
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Figure 2-4

2.5

Web services

What are web services? Web services are based on open standards (XML, SOAP, WSDL) and enable establishing connections between software components. Due to the standardization, this connection is independent of programming languages, platforms or operating systems (as opposed to the COM model by Microsoft). This enables software components (clients) to call other software components (services) and use their functionality. The software components can be located on the same PC or any networks be interconnected (e.g. Internet/Intranet). For the client to use the web service, this does not make any difference (apart from the different data runtime between client and server).

V1.0

26.04.05

18/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Components of a web service The following table describes the four most important components of a web service (see link \7\).
Table 2-9

Component Service

Description A software component which is capable of processing data from XML documents. The XML documents can be transferred from one client to the service in any manner. Frequently used is the transport via HTTP. How the service processes the information of the XML document is not important for now. The result of the processing is sent to the client in an XML document. The XML document, which is sent to the service, is the most important feature of web services. It contains all applicationspecific information. The documents which are exchanged between a client and the service, correspond to a certain XML scheme. This ensures, that both sides generate and process valid XML documents. The XML scheme, to which both sides must have access, is referred to as WSDL (Webservice Description Language, see below). The address of the server specifies where it can be found when using a certain protocol (e.g. HTTP). The envelope is a protocol for encapsulating the XML document. This ensures, that the service-specific information of the XML document can be clearly separated from other information which could be exchanged between the client and the server. The protocol used for this is SOAP (see above).

Document

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Address Envelope

Operating description with WSDL In order for a client to use a web service, it must know which operations the web service has provided. Furthermore, the client must know how the XML documents or SOAP messages for communication between client and web service are structured. For this purpose, the operating description can be polled for each web service in WSDL format (Webservices Description Language). The operations of the web service which can be called by the client are defined in WSDL. This includes the parameters for these operations as well as the structure of the XML documents or SOAP messages required for calling these operations. The Microsoft Visual Studio .NET development environment can use web services and automatically reads the WSDL information. This provides the functions of the web service to the user (see 2.6 Including a web service in Visual Studio .NET).

V1.0

26.04.05

19/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

An example for a web service The OPC Foundation (an interest grouping of well-known manufacturers for the further development of the OPC standard) provides a web service for accessing an example OPC server. The address of the web service is: http://opcfoundation.org/XmlDaSampleServer/Service.asmx. Clicking the link opens the web service in a web browser. The displayed website is automatically generated by the web service and lists the available operations of the web service. Clicking the displayed operations displays the respective SOAP messages (SOAP Request and respective SOAP Response). These telegrams show which parameters are transferred to the operation and which return values are delivered by them. Clicking on Service Description displays the respective WSDL file.
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

2.6

Including a web service in Visual Studio .NET

Introduction This chapter explains how to use a web service in your .NET application. It does not make any difference here, which .NET programming language you use (C++, C# or Visual Basic .NET) or which application you realize (Windows application or ASP.NET web application), as the development environment used here (Visual Studio .NET 2003) is always the same. In the following part, the OPC-server web service of the OPC Foundation will be integrated into a Windows application. The programming langue used is Visual Basic .NET. Generating a new Windows application In this section you learn how to create a new Windows application using the programming language Visual Basic .NET in Visual Studio .NET 2003. If you wish to integrate the web service into your own application, you can skip this section.
Table 2-10

No. 1

Instructions Start Visual Studio .NET 2003 with: Start Programs Microsoft Visual Studio .NET 2003 Microsoft Visual Studio .NET 2003 Open the "New Project" window by selecting: File New Project...

Note

V1.0

26.04.05

20/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Make the following settings: Project types Visual Basic projects Templates: Windows applications Name Name for your application Save as Filing path for your project

4 Create the new project with OK.

The new project is generated and opened.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

21/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Integrating a web service Here you will learn how to integrate a reference to a web service into an existing Visual Studio .NET 2003 project. This will be explained using the example of the OPC-Server web service of the OPC Foundation. This requires your PC being connected to the internet.
Table 2-11

No. 1

Instructions In the project folder explorer you open the context menu of your project and select Add web reference...

Note

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

In the URL field you specify the URL of the OPC-Server web service of the OPC Foundation: http://opcfoundation.org/XmlDaSampleServer/ Service.asmx Click the Go to button. The service description of the web service is displayed.

If the error message is to be displayed on the right, your proxy settings are configured automatically. However, Visual Studio .NET cannot use the automatic settings. Therefore, you need to adjust your proxy settings. To do this, please follow the steps below: 1. Open the internet options with: Start Settings (Control Panel ) Internet Options. 2. In Internet Properties you select the Connections tab. 3. Open the LAN settings with the LAN Settings... button (at the very bottom). 4. Mark the checkbox Use a proxy server for your LAN.... 5. In the fields Address and Port you enter address

V1.0

26.04.05

22/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

No.

Instructions and port of your proxy server. Should you not know these details, please request them from your network administrator. 6. Confirm all details with OK and perform steps 2 and 3 in Visual Studio once more.

Note

As soon as the web service has been found, a name is suggested in the field Web reference name. You can change it or keep it. Add the web reference to your project with Add reference. Den Webverweis sehen Sie nun im Projektmappen-Explorer:

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Utilizing the functions of a web service After including the web reference into your project, the operations of the web service can be utilized in your program. First, you create a new name space for all relevant web service components using the WSDL information. This name space contains all classes required for the access to the operations of the web service. These classes are so-called proxy classes which enable accessing the actual operations of the web service. They encapsulate the entire communication to the web service via SOAP and HTTP and need not be further attended to with regards to program technology. This equally enables accessing the operations of the web service as well as the methods of any other class. The classes of a web service in the object browser The classes of a web service can be displayed in the object browser. All methods and properties of the individual classes can be viewed there. Access to the operations of a web service The access to the web service from the program then occurs via creating a new instance of the web service class. The operations of the web service can then be called via this instance. This is illustrated in the figure below.

V1.0

26.04.05

23/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA
Figure 2-5

Entry-ID: 21402169

2.7
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Function mechanisms of.NET Framework

Introduction .NET Framework is a development and execution environment. They enable the interaction between different, .NET-capable programming languages and libraries for creating .NET applications. These .NET applications are, similar to Java, not directly compiled to the machine code running directly on the CPU of the PC, but compiled into an intermediate language. This intermediate language is only compiled to machine code by a special runtime environment when starting the application. Overview The following figure shows the structure of.NET Framework. The individual components are described in the following sections.

V1.0

26.04.05

24/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA
Figure 2-6

Entry-ID: 21402169

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

WIN32 API Win32 API (Application Programming Interface) is the basis of .NET Framework. Win32 API provides system functions. These system functions are used by Windows applications, in order to gain access to the operating system. Common Language Runtime (CLR) Common Language Runtime (CLR) is based on Win32 API. It constitutes a runtime environment comparable with a Java Virtual Machine model. It compiles Just In Time (JIT), a type of byte code, into machine code (which depends on the respective processor architecture). Microsoft refers to it as IL-Code (Intermediate Language). Intermediate Language, Garbage Collector and unmanaged Code The advantage of the IL code is the fact that it is independent of the platform. It is also possible to execute this code on Linux (Unix) systems, if a CLR has been implemented there (i.e. http://www.mono-project.com/). The CLR does not only perform the JIT compiling of the IL code, but also the entire memory management. Similar to Java, a Garbage Collector (GC) was developed, who releases un-referenced memory areas within the CLR after an unspecified time. Code subjected to the access of the Garbage Collector is also referred to as managed Code. In order for it to be possible in certain cases to still control the release of memory areas manually, the developed code can be declared as "unman-

V1.0

26.04.05

25/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

aged". This enables protecting certain code areas or entire programs explicitly from the access of the Garbage Collector. Base Classes Regarding the libraries of partly varying extend of the classic Windows world, Microsoft has now implemented a uniform base class library which can be accessed independently from the .NET programming language. Visual Studio .NET Visual Studio .NET provides a uniform development environment for the different .NET languages. This enables realizing .NET components in different languages. Interaction between the .NET components is possible with Visual Studio .NET without greater efforts.
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Mainly the easy to handle integration options within the .NET components enable a faster development.

2.8

ASP.NET

Introduction ASP.NET is a technology by Microsoft for creating dynamic web applications. ASP stands for Active Server Pages, with ASP.NET being a continued development of ASP. As opposed to static html-pages, ASP.NET (as well as the predecessors ASP, DHTML or Javascript) enable displaying pages with dynamic contents (e.g. results of calculations) in the web browser. As already referred to by the name ASP, the program logic of the web application runs on the server and is independent of application displays in the browser of the client. The client will not notice any of this and only receives the result of the program logic as an html-page. ASP.NET is part of .NET Framework. This allows to create the web applications with each .NET-compatible programming language (e.g. Visual Basic .NET, C# or J#). Further information at \12\. Overview of the functionality The following figure shows the sequence during requesting an ASP.NET page from the client.

V1.0

26.04.05

26/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Figure 2-7

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description of the functionality The sequence of the request is further explained here.
Table 2-12

No. 1

Description The client sends a request to the web server (via http) from the internet browser. This may be the call of an ASPX page (which are always ASP.NET applications) or pressing a button on the ASPX page. The Web server recognizes the request as an ASP.NET request and forwards it to the ASP.NET application. Depending on the request, certain functions are called in the program code of the ASP.NET application. At the first call of the program code of the ASP.NET application, it is compiled into Intermediate Language (IL) by .NET Framework, and executed in the Common Language Runtime (CLR) of .NET Framework. The program code of the ASP.NET application now generates a dynamic ASPX page and transfers it to the web server. The web server forwards the generated ASPX page to the client (via HTTP).

2 3 4

5 6

Life cycle of an ASP.NET page During each call of an ASPX page by the web server, the pages runs through various states on the server, which are described as life cycle. The

V1.0

26.04.05

27/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

following table illustrates the life cycle of an ASPX page in its temporal sequence.
Table 2-13

State Initialization Loading the display status Processing returned data Loading the page Returning the change notification Returning the event handling Phase before page display Saving the display status Page presentation Unloading the page

Description Initialization of settings which are to apply to the entire duration of the request. The display status is a list of name/value pairs in which control elements and the page itself store all information which must be permanently available beyond web requests. Processing form data, e.g. if the text of a text box has changed, a respective event is triggered in the server. Loading the page with all control elements and all other, required data, e.g. database inquiries. If the status has been changed compared with the previous status, a respective method is called. Calling a server code which was triggered by the client (e.g. by clicking a button). Preparing the display of the page. Executing short-term updates. The display status of all control elements are saved as well as the entire page. Displaying the page. The last life signal of the page, prior to being deleted. Serves for releasing critical resources.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

28/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Important ASP.NET features


Table 2-14

Feature .NET Framework

Description The integration of ASP.NET in into .NET Framework enables access to the complete functionality of .NET Framework from the web application. This includes utilizing all .NET-compatible programming languages. The program code (IL) of an ASP.NET application is compiled to machine code when first calling the CLR (therefore, the first call of an ASPX page causes a delay for the following calls). This provides a performance advantage compared with previous ASP applications (where program code is interpreted for each call). Web forms can be used for generating form based websites. You can use ASP.NET server control elements, for creating general elements of the user interface, and program them for general tasks. With these control elements, web forms can be generated very quickly from reusable, integrated or user defined components, so that the code of a page is simplified.

Compiled code

Web Forms

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

29/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Saving variables in an ASP.NET application As described, the transfer of ASPX pages is based on HTTP. This protocol being stateless, it is not possible without difficulties to save states (e.g. of variables or even whole instances of classes) throughout several calls. If a page is called by a client, the server initially does not know whether the same client has called this page before or not. ASP.NET offers different options of saving data throughout several page calls. Three possibilities are described in the following table. In this application, the session state is used.
Table 2-15

State ViewState

Description Saves the state of the page throughout several calls of the same page (e.g. forms). The state includes the status of input fields and other control elements on the page, but also user defined data. For saving the ViewState, a hidden field named __VIEWSTATE is used on the website. The state is written to this field in coded format. Due to the fact, that the field is located in the website itself, the ViewState data is sent from the client to the server and back with each call. The more data are saved in ViewState, the larger the data volume to be transferred (cost + time!). Saving data: ViewState("[any name]") = Data Read data: Data = ViewState("[any name]") A session ranges over the entire period of time in which a client uses a certain web application. Data saved in session state always remain on the server. This keeps the data volume to be transferred very low. The identification of a session occurs either by means of a cookie (see Glossary) or by means of a session ID in the URL assigned to each client by the server. Saving data: Session("[any name]") = Data Read data: Data = Session("[any name]") The application state contains data and information which apply for the entire web application as well as for each user (client). The application state is filed in the main memory of the server and is not persistent (i.e. after terminating the web server these data are lost). Saving data: Application("[any name]") = Data Read data: Application("[any name]") = Data

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Session state

Application state

V1.0

26.04.05

30/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

2.9
Overview

Safety settings of an ASP.NET application

The following figure illustrates the safety aspects to be considered in the course of this application. The ASP.NET application, or the web service respectively, are further discussed below. The mechanisms in bold print were realized in the application on hand.
Figure 2-8

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

31/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Authentication
Table 2-16

Method Windows integrated

Description When using the integrated Windows authentication, no further authentication needs to be performed in the ASP.NET application. It is performed completely by the IIS web server. Thereby the Windows user accounts which exist on the server are used for the authentication of the client. This method is used for this application. This authentication method does not use the Windows user accounts on the server. When the client calls a protected site, the server will divert him to a login-page. There the client enters a user name and a password. If they are valid, the client receives a so-called ticket from the server. It is limited in time and is saved on the client computer as a cookie. Using this ticket, the client can now access the protected sites. This authentication method is not further considered within this application. This requires the Microsoft Passport SDK (Software Development Kit). The authentication occurs with the Microsoft Passport user database on the internet. User information of all registered passport users are filed there. This service is used, for example, by the e-mail service hotmail by Microsoft. Hoverer, the Passport-service by Microsoft is not free of charge, therefore it will not be used in this application.

Form based

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Passport

Defining the authentication method Defining the authentication method for an ASP.NET application is relatively simple. It occurs in the configuration file web.config of the ASP.NET application. The following figure displays a section from this configuration file. In the "authentication" element, in the attribute "mode", the type of authentication is specified. For this application, the value is "Windows", as the integrated Windows authentication is used. Further possible values are "Forms", "Passport" or "None".
Figure 2-9

V1.0

26.04.05

32/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Authorization
Table 2-17

Method URL authorization

Description Verifying the data access with ASP.NET on the basis of the requested URL (e.g. "http://localhost/app/mainform.aspx"). It is configured in "web.config". This way, the access to the respective ASP.NET application can be explicitly allowed or denied for certain users or user groups. In this application, the access to the ASP.NET application is restricted to members of the user group "Users". The standard setting (preset: access to all users permitted) has been set in the global configuration file machine.config. See also 2.2 Safety aspects of the Internet Information Services When starting the ASP.NET application from a client, it is executed on the server with the user account ASPNET (if no impersonation is used, see below). You must ensure that the data required by the application are allowed for the user "ASPNET", which normally will be the case. This method enables you to define in the source code of the ASP.MET application whether the current client is authorized to access certain resources or execute certain operations. You verify the client by his user name and/or its respective user group. This functionality is not performed in this application directly. However, a brief example is described in the source code of the application as a comment.

File authorization

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

.NET-Roles

Setting the authorization in the "web.config" file The following figure shows the authorization settings for the application on hand. Here, only the user "OPC-Client" has access to the ASP.NET application ("allow" element). All other users are denied access (deny element)
Figure 2-10

V1.0

26.04.05

33/93

Function Principles and Program Structures General Function Mechanisms


Data Exchange via XML-DA Entry-ID: 21402169

Impersonation If an ASP.NET application is called by a client, it will normally be executed on the server under the user account "ASPNET". This account is member of the group Users which gives it relatively few permissions. If you wish to grant the clients individual permissions during executing the ASP.NET applications (by data authorization), you can use Impersonation. The ASP.NET application on the server takes on the identity of the client (on the server it runs under the user account to which the client has logged on). Now the same access permission on file levels apply for the ASP.NET as for the user account of the client. The Impersonation is defined in the configuration file web.config of the ASP.NET application. However, as Impersonation is not used in this application, it is not further discussed here.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

34/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Function Mechanisms of this Application


the functionalities offered by the OPC XML-DA interface, such as structure of the data interface between controller and head-end, how OPC items are managed in the Windows application, and how the Windows application is structured.
Table 3-1

Here you will find information on

Chap. 3.1 3.2 3.3


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Title The OPC XML-DA interface Synchronous and asynchronous methods of the OPC XML-DA interface Used objects and methods of the XMLDA interface Cyclic reading of process values (subscriptions) Data flow model Logic data interface between controller and OPC client Managing the OPC items in the OPC client Structure of the Windows application Structure of the ASP.NET application

Relevance general general general general general general Windows application Windows application ASP.NET application

Page 35 39 41 42 43 45 48 49 52

3.4 3.5 3.6 3.7 3.8 3.9

3.1

The OPC XML-DA interface

Data Access interfaces of the SIMATIC NET OPC server The figure below illustrates the Data Access interfaces available in the SIMATIC NET OPC server. The left half represents the "classical" interfaces based on COM. The right half represents the new interface based on a web service and SOAP.

V1.0

26.04.05

35/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA
Figure 3-1

Entry-ID: 21402169

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

What is OPC XML-DA OPC XML-DA (Data Access to an OPC server via XML) is, like the classic OPC Data Access, an interface for variables of an OPC server. This is, however, completely platform independent (unlike for the COM technology used for OPC Data Access) and is also supported by the development environment Visual Studio .NET. Data access by means of OPC XML-DA has a function scope based on OPC Data Access, however, only write and read services are available. Change controlled feedback messages about data changes, like for COM or DCOM OPC DA interfaces, are not planned for OPC XML-DA due to the loose internet connection (see 2.1 Internet Information Services (IIS)). SOAP vs. DCOM In this application the utilization of the SOAP based OPC SML-DA interface has priority. Due to the fact that COM technology, or respectively DCOM beyond computer boundaries, were used so far, SOAP and DCOM are now being compared here.

V1.0

26.04.05

36/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Table 3-2

Advantages SOAP DCOM Platform independent (client side) Simple administration as based on HTTP and XML Enables feedback from server to client Higher data throughput

Disadvantages Not suitable for transferring large data volumes A web server is required at the head-end Windows-based Not directly supported by .NET Complicated administration

Security settings for OPC XML-DA Web Service Apart from the access protection to the OPC server, which can be configured in STEP 7, you can configure an additional access protection for OPC XML-DA web service. OPC XML-DA web service being an ASP.NET application, it has a configuration file "web.config". As described in chapter 3.1 The OPC XML-DA interface, the authentication and authorization method for the web service can be defined in "web.config". The "web.config" of the OPC XML-DA web service is available at: "\[Siemens installation directory]\SIMATIC.NET\opc2\binXML\" The "web.config" of the OPC XML-DA web service is available in this application The following figure illustrates the user-defined settings of the "web.config" of the OPC XML-DA web service for this application. The "authentication" element was kept at the standard value (mode="Windows"). The "authorization" element with its sub-elements was added (see "Demonstration" part of this application).
Figure 3-2

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Access permissions granted by "web.config" The above section of the "web.config" of the OPC XML-DA web service grants the following access permissions:

V1.0

26.04.05

37/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Access allowed for the user "OPC-Client" and "ASPNET" on the PC "Head-end". Access denied for all other users

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

38/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Important differences to the DA 2.05 interface of the OPC server Compared with the (classic) DA 2.05 interface of the OPC server, the OPC XML-DA interface has the following differences: The access to the OPC items is only allowed via the item-ID, there is no special OPC item object. There are no Client- or ServerHandles for the individual OPC items. The OPC items are not organized in OPC groups. On being called, the operations (e.g. reading or writing) are given a so-called item list, which contains the item-IDs. Resource handling needs not be focused on, unlike for the DA interfaces based on COM mechanisms. With the exception of subscriptions, all write and read operations are performed directly to the controller (the DEVICE). The subscription ping rate corresponds to the UpdateRate at OPC group objects. The XML-DA interface does not contain an OnDataChange mechanism, i.e. the server cannot automatically inform the client of a changing process variable. Subscriptions are used for this, which must be polled after a certain time defined by the OPC client. Logging off the OPC client at the OPC server is not possible. When establishing the connection, it is verified whether the OPC server exists. When accessing the OPC server, it is started. If within a timeout interval there is no access to the OPC server, it is stopped again.


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

3.2

Synchronous and asynchronous methods of the OPC XML-DA interface

Introduction The methods of a web service are principally asynchronous. This means, that the client sends a request (SOAP request) for processing a method to the web server. After the web service terminates processing, it sends the result back to the client (SOAP response). The time when the web service returns the result is not defined. After sending the SOAP Requests the client can continue with program processing and needs not wait for the SOAP Response (asynchronicity). However, if the web service does not respond to a request within a given period of time (Timeout), an error is output by the called function. The timeout interval can be defined by the user. The methods of the OPC XML-DA web service can be called asynchronous as well as synchronous (whereby Request and Response are combined in one call).

V1.0

26.04.05

39/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Data flow diagrams for synchronous and asynchronous functions The following figure illustrates the difference between an asynchronous (25) and a synchronous call (6-9) of the same operation in the web service. In the normal program sequence (1) an asynchronous function is called first, and then a synchronous function. A precise explanation of the processes occurs directly after the diagram. Irrespective of whether a synchronous or an asynchronous function is called, SOAP request and SOAP response are always the same for the same web service operation (3 = 7, 4 = 8). The graphic also applies for remote OPC clients.
Figure 3-3

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Asynchronous methods From the normal program sequence (1) the method for sending a request is called first (2). The method names for sending a request starts with Begin (e.g. BeginRead()). The name of the function to be called when the web service has processed the request, is transferred to the callback parameter. The method then generates a SOAP Request and sends it to the web service (3). After sending the SOAP request, the client can continue with program processing. If the web service has terminated the request, it sends a SOAP response to the client (4). The callback function is thereby called. The web service result is polled with an end-method, e.g. EndRead() (5).

V1.0

26.04.05

40/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Principally, asynchronous method calls are suitable for executing options with a higher data volume and longer runtimes. The operation runs in the background and the user interface can still be operated. Synchronous methods These methods consists only of a method call (e.g. Read() ). After the method was started (6), the program initially continues being executed. The method first generates a SOAP Request and sends it to the web service (7). Then it waits until the SOAP response is returned by the web service (8). During this wait time the program is stopped. After receiving the SOAP response, the program is continued (9). If the response of the web service does not occur within the timeout interval, the method is terminated with an error (an exception is triggered). Due to the fact, that synchronous methods interrupt the program sequence, the program cannot be operated during the call. Therefore, long execution times of synchronous methods (e.g. at high data volumes) should be avoided or asynchronous methods be used.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

3.3

Used objects and methods of the XML-DA interface

Introduction This chapter provides you with an overview of the methods or operations of the OPC XML-DA web service used in this application. Irrespective of its actual implementation in the source code of this application, the execution of these methods are described as synchronous methods. A detailed description of the functions are available in the commented code as well as in 4 Explanations on the Example Program. RequestOptions These are call options, which are transferred to each method of the XMLDA interface. Here you can define, whether after executing the operation the XML-DA interface returns certain values for each of the affected OPC items. These include e.g. item name, time stamp or diagnostics information. GetStatus A GetStatus request verifies the web service and queries manufacturerspecific information, which are not accessible to other OPC methods. The most important information hereby is the operation status of the OPC server ("running", "failed", "noConfig" etc.) Browse The browse method is used for navigating within the hierarchical address space of the OPC server. It can be used for displaying all process variables existing in the address space of the OPC server.

V1.0

26.04.05

41/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Write (Read) The Write method executes a write job for one or several items, whereby each item represents a process variable. Analog, the Read method executes a read job for one or several items. Further methods Further methods used are Subscirbe, SubscriptionPolledRefresh and SubscriptionCancel. These are discussed in greater detail in the following chapter. Comparing the Read and SubscriptionPolledRefresh methods The following table compares the Read method with the SubscriptionPolledRefresh method (see following chapter for them as a component of a subscription). It shows, which method is suitable for cyclic (i.e. continuous monitoring) and which method is suitable for acyclic reading of process variables.
Table 3-3

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Operation Cyclic reading Acyclic reading

Read +

SubscriptionPolledRefresh + -

3.4

Cyclic reading of process values (subscriptions)

Introduction The OPC XML-DA web service offers the client the possibility of establishing a loose connection to the OPC server throughout several method calls. The client has the option of logging on a Subscription at the web service. When logging on, the client transfers the list of items (i.e. process variables) which should be contained in the subscription. The client can continuously poll the logged on subscription (polled refresh). With each polled refresh from the client, the web service returns those items including values, whose values have changed since the last polling. This mechanism helps reduce the latent time until completion of the value changes of a process variable, as well as reducing the communication load between client and server. Overview The following figure gives a clear overview of the life cycle of a subscription. The three phases, logging on, polling, and logging off of a subscription are described below.

V1.0

26.04.05

42/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Figure 3-4

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Logging on a subscription ("Subscribe" method) The subscribe method is used for logging on a subscription at the web service. The client transfers a so-called Itemlist to the web service as well as various options. This Item list contains all items which the web service is to monitor for changes within the framework of this subscription. The parameter "SubscriptionPingRate" (in mili-seconds) determines the time interval in which the server verifies the existence of the client. If the client has not communicated with the server within the specified period of time, the server can release all resources necessary for the subscription process of the client. The method returns the ServerHandle (data type string) for this subscription. This ServerHandle is used to identify the previously logged on subscription during all following calls. When requested, the method also returns the actual values of the items in the item list. Polling a subscription ("SubscriptionPolledRefresh " method) With this method, the client requests from the server (web service) an update of those items transferred when the subscription is logged on. The client transfers the previously received ServerHandle to the server. The response from the web service contains an item list, which contains items which have changed their value since the last polled refresh of the subscription. Depending on which options were selected during logging on the subscription, the web service delivers additional information for each item, e.g. time stamp, item name, etc..

V1.0

26.04.05

43/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Logging off a subscription ("SubscriptionCancel" method) With this method the client logs off the subscription at the web service with the given ServerHandle. The web service can then release the respective resources.

3.5

Data flow model

Introduction This chapter explains the data flow model of the XML-DA interface of the SIMATIC NET OPC server. Here you will learn how the individual methods of the XML-DA interface exchange data with the controller. Overview The following figure shows an overview of the three methods of the XML-DA interface, which are used for exchanging process variables. These are: polling a subscription (Refresh, 1 + 2), direct reading of process values from the controller (Read, 3) writing process values into the controller (Write, 4).

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Figure 3-5

V1.0

26.04.05

44/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Explanation The following table further explains the data flow for the three discussed methods.
Table 3-4

No. 1

Explanation Polling a subscription always delivers values taken from a cache memory of the OPC server. So this polled refresh always delivers the value of a variable whose value has changed since the cache was last updated. The cycle time at which the cache is updated is defined when configuring the OPC server in the STEP 7 project. As soon as a subscription is logged on, the OPC server starts the cyclic update of the cache.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

The "Read" method always reads the current process value (irrespective of whether the call is synchronous or asynchronous). Each Read request to the OPC server causes the server to read the process value from the controller and to return the current value to the OPC client. It must be noted that frequent reading of a large number of process values, possibly even from several clients, may lead to an increased bus load and communication load of the controller. A subscription should therefore always be used for a cyclic polling of process values. Process values are written directly to the controller. Each Write request to the OPC server causes the server to immediately write the new value to the controller (depending on the access permissions granted in the configuration).

3.6

Logic data interface between controller and OPC client

Introduction In this chapter you will learn which process variables of the controller are accessed in the OPC client and how the respective OPC items are structured in the OPC client.

V1.0

26.04.05

45/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Visualized process variables The interface to the head-end is, on the controller side, implemented with three data blocks. The contained variables represent the process values of the simulated mixing process. The following table describes the setup of the data blocks.
Table 3-5

DB Data_Act_Val

Variable Act_Cooler Act_Heater Act_InValve1 Act_InValve2 Act_Mixer Act_Niveau Act_OutValve Act_Temp Act_Time

Data Type BOOL BOOL BOOL BOOL BOOL REAL BOOL WORD DATE_AND _TIME BOOL REAL REAL WORD WORD WORD

Description Current state cooler Current state heater Current state inlet valve 1 Current state inlet valve 2 Current state mixer Current filling level in tank Current state outlet valve Current temperature in tank Current system time on S7 Start mixing process Setpoint value level 1 Setpoint value level 2 Setpoint value maximum temperature Setpoint value outlet temperature Setpoint value inlet temperature

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Data_Control Data_Rat_Val

Start_Auto Rat_Niveau1 Rat_Niveau2 Rat_Temp_Max Rat_Temp_Out Temparature_In

V1.0

26.04.05

46/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Access of OPC server to process variables The access of the OPC server to the process variables of the S7 controller occurs via a configured S7 connection. This connection has already been configured with the NetPro tool in the respective STEP 7 project. For using the XML-DA interface, it is not important whether the S7 connection has been realized as a unilateral or bilateral connection (in this application it is unilateral). The symbolic access to all process variables is also configured in the STEP 7 project (in the Properties dialog of the OPC server in the NetPro tool). The symbolism of the variables in the OPC server is structured as follows: [Station name].[CPU name].[DB name].[Variable] e.g.: SIMATIC 300(1).CPU 315-2 DP.Data_Act_Val.Act_Temp Managing the OPC items
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

For accessing the process variables from the OPC client, so-called item lists are used at the OPC XML-DA interface. These item lists contain an array of items. These items have different properties, which depending on the requirement can be set differently. These properties include, for example, the item name (the symbolic or absolute address of the OPC item), the item value (either of the value to be written or the value to be read) and the time stamp (assigned by the OPC server). For an OPC XML-DA client to be able to access the process variables via the web service, the service must transfer the respective item lists (the Request-ItemLists) to the web service. The OPC items returned by the web service are also packaged by the service into item lists (ReplyItemLists).

V1.0

26.04.05

47/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Used item lists In this application, the used process variables are managed in three different item lists. The following table shows the item list as well as the contained OPC items.
Table 3-6

Itemlist SubscriptionList

Description This list contains all process variables to be monitored. They are registered at the web service via a subscription. During polling of the subscription (SubscriptionPolledRefresh) all changes at the process values are reported to the client.

Variables Act_Cooler Act_Heater Act_InValve1 Act_InValve2 Act_Mixer Act_Niveau Act_OutValve

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Act_Temp Act_Time Start_Auto Rat_Niveau1 Rat_Niveau2 Rat_Temp_Max Rat_Temp_Out Temparature_In WriteSetpoints This list contains the setpoint values required for this application. If a write request is triggered, this list is transferred to the write method. Per method call all setpoint values are written to the controller. This list only contains a boolean variable. Rat_Niveau1 Rat_Niveau2 Rat_Temp_Max Rat_Temp_Out Temparature_In Start_Auto

WriteAuto

3.7

Managing the OPC items in the OPC client

Solution realized in the Windows application Encapsulating data describing an OPC item into its own class offers almost unlimited expandability. This has been realized by means of the OPCItemExtender class. All OPCItemExtender objects are saved in an object of the OPCItemExtenderList class, which in return is a specialization of the System.Collections.ArrayList class of the .NET-Framework.

V1.0

26.04.05

48/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Conventions of the OPCItemExtender and OPCItemExtenderList objects In order for the client and server handles not to be managed separately, the following conventions must be made: The client handle of an OPC item is the index of an OPCItemExtender object within the OPCItemExtenderList object. There are two ways to receive an OPCItemExtender object from the OPCItemExtenderList: Index access to the list (index corresponds to the client handle) Specifying the ITEM_ID, which should always be known in the application (e.g. in form of constants, #define directives, INI files)

The Hashtable of the OPCItemExtenderList For also enabling performing the last point (accessing an OPCItemExtender object via its ITEM_ID) at over 1000 objects with acceptable performance, the OPCItemExtenderList contains a hash table, which contains the ITEM_ID as keys, and a reference to the respective OPCItemExtender object as value. This enables accessing any OPCItemExtender object in constant time (O(1) complexity). Access to a particular OPCItemExtender object via the hash table The following figure schematically illustrates the explanation above. This also enables code constructs discussed in the following blocks.
Figure 3-6

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

3.8

Structure of the Windows application

Class model
Figure 3-7

V1.0

26.04.05

49/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Note

Only the most important relationships and attributes are depicted. Relationships with standard .NET controls or structures also necessary for this application are not depicted. This is available in the commented source code.

V1.0

26.04.05

50/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Explanation of the most important classes The most important classes are explained in the above class diagram.
Table 3-7

Class MainForm

Description The main window of the application. Here all process variables are visualized and all other classes are being referred to. In this class, all accesses to the XML-DA interface of the OPC server are encapsulated. This includes connecting to the OPC server, browsing of the address space of the OPC server, as well as verifying the current state. This class encapsulates all methods for accessing a subscription. For each subscription an own instance of the class is created (in this application only one subscription is used). Initially the items to be contained in the subscription are transferred to this subscription class. Then the subscription is logged on. The cyclic polling of the subscription is automatically performed by the class. The refreshed values are transferred via an event. This class encapsulates all Methods for writing process values to the controller via the XML-DA interface. Writing occurs via the Write method of the class. The items to be written are transferred to this method. If the write command was executed successfully, the current values are transferred from the controller to the calling class via an event. Analog to that, the XMLOPCReadManagement class realizes all methods for reading process values. See 3.7 Managing the OPC items in the OPC client

XMLOPCServerManagement

XMLOPCSubscriptionManagement
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

XMLOPCWriteManagement

OPCItemExtender

V1.0

26.04.05

51/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

3.9

Structure of the ASP.NET application

Class model
Figure 3-8

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Note

Only the most important relationships and attributes are depicted. Relationships with standard .NET controls or structures also necessary for this application are not depicted. This is available in the commented source code.

V1.0

26.04.05

52/93

Function Principles and Program Structures Function Mechanisms of this Application


Data Exchange via XML-DA Entry-ID: 21402169

Explanation of the most important classes The most important classes are explained in the above class diagram.
Table 3-8

Class MainForm

Description The user interface of the application in the web browser. Here all process variables are visualized and all other classes are referred to. In this class, all accesses to the XML-DA interface of the OPC server are encapsulated. This includes connecting to the OPC server as well as verifying the current state This class encapsulates all methods for accessing a subscription. Initially the items to be contained in the subscription are transferred to this subscription class. Then the subscription is logged on. The cyclic polling of the subscription is triggered by a Java script on the client. The refreshed values are then written into the user interface. This class encapsulates all methods for writing process values to the controller via the XML-DA interface. Writing occurs via the Write method of the class. The items to be written are transferred to this method. If the write command was executed successfully, the current values are transferred from the controller to the calling instance.

XMLOPCServerManagement XMLOPCSubscriptionManagement

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

XMLOPCWriteManagement

V1.0

26.04.05

53/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Explanations on the Example Program


the concrete realization of this application. The structure of the S7 program as well as the most important program sequences of the Windows application are illustrated below.
Table 4-1

Here you will find information on

Chap. 4.1 4.2 4.3 4.4


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Title Explanation for the simulation program (S7 program) Saving the configuration data Windows applications ASP.NET application

Relevance general general Windows applications ASP.NET application

Page 54 55 57 68

4.1

Explanation for the simulation program (S7 program)

Introduction Since the S7 program is not the main focus of this application, only a brief description of the functionality of the simulation program is given here. Process description The S7 control program simulates a mixing process. Liquids are hereby fed into a tank via two inlet valves. As soon as the tank has been fill up, the liquid is mixed and heated up. After the setpoint temperature has been reached, the liquid is cooled down again and then drained via an outlet valve. The process variables for the data exchange with the OPC server are saved to three different blocks.

V1.0

26.04.05

54/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Program structure The following figure shows the call structure of the S7 program.
Figure 4-1

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

4.2

Saving the configuration data

Introduction The configuration data for this application is saved in an XML file. All main settings for data exchange via the OPC XML-DA interface can be set by the user. The "ConfigManager" class The functions for accessing the configuration data in the XML file are implemented in the "ConfigManager" class. The.NET methods "XmlSerializer.Serialize" and "XmlSerializer.Deserialize" are used for this. Both functions are described in greater detail in the following table.
Table 4-2

Function Serialize

Description Automatically serializes a transferred object (in this case the "ConfigData" class described below) into an XML file. The format of this XML file can be viewed in the section "The Options.xml configuration file". Reads the given XML file and creates the given object (here: "ConfigData" class).

Deserialize

V1.0

26.04.05

55/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

The "ConfigData" class The following figure illustrates the configuration data stored in the ConfigData class. Apart from the address of the web server, this also includes the symbolic name of the OPC item.
Figure 4-2

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

The "Options.xml" configuration file The figure below contains the XML file "Option.xml" which was serialized from the "ConfigData" class. It is available in the program directory of the application (installation of the application: see Demonstration part of this application). The Data element stores the entire information of the ConfigData class and it can also be changed manually.
Figure 4-3

V1.0

26.04.05

56/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

4.3
4.3.1

Windows applications
Connecting to the OPC server

Introduction The entire functionality for the server management (connecting and disconnecting the OPC server) is encapsulated in the "XMLOPCServerManagement" class. The most important code sections of this class are discussed in greater detail below. The class is used in the Windows application as well as in the ASP.NET application. However, there are some architecture related small differences between both applications. These differences do not relate directly to using the OPC XML-DA interface and are not discussed here in greater detail (see source code of the application). Verifying the availability of the web service
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Table 4-3

Description Position Code extract XMLOPCServerManagement.ServerConnect

Description

The "OPCRequest" object establishes a connection with the web server by transferring the address of the web service to the object ("m_ServerName"). The "GetResponse" function requests a response from the web service. The response itself is not important. If no connection can be established, no error occurs and the program can be continued. In case of an error, an exception is thrown, which is discussed in the next section.

V1.0

26.04.05

57/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Transferring credentials to the web service (authentication)


Table 4-4

Description Position Code extract XMLOPCServerManagement.ServerConnect (ASP.NET application)

Description

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

If an authentication for the web service is required, the GetResponse method described in the previous section throws an exception (this also means that the connection to the web service could be established successfully). This exception is of the type "WebException" and has the state "ProtocolError". The authentication information is transferred in form of credentials, which are located in a so-called CredentialCache. With the Add function a new credential is created in the cache. The "CredentialsDlg().GetCredentials" function displays a dialog which prompts the user to enter user name and password for this new credential. The "m_OPCDataAccess" object is of the type "OPCXML_DataAccess" and represents an instance on the web service. The property "Credentials" of the "System.Net.ICredentials" type contains the authentication information for the web service. The CredentialCache is transferred to this property.

Verifying the operating status of the OPC server


Table 4-5

Description Position Code extract XMLOPCServerManagement.ServerConnect

Description

After the accessibility of the web service has been verified, and necessary logon information transferred, the operating status of the OPC server is verified. First the address of the web service is transferred to the "Url" property of the "m_OPCDataAccess" object. The method "GetStatus" verifies the operating status of the OPC server. "m_OPCReply" contains the response of the web service.

V1.0

26.04.05

58/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

The "GetStatus" method


Table 4-6

Parameter LocaleID As String ClientRequestHandle As String Status As Server Status en "1"

Value

Description Optional attribute used by the client to define the language for certain returned data. Optional and in this example user-definable. In complex systems, this detail helps the client allocate requests and responses. Contains the status information on the OPC server, such as version, producer, etc..

"m_OPCStatus"

4.3.2

Writing process values (reading analog to this)

Introduction
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

The entire functionality for writing process values into the controller is encapsulated in the "XMLOPCWriteManagement" class. This class is also used in both applications of this application example. The existing differences in the class are documented in the source code of the respective application. Collecting items in an item list
Table 4-7

Description Position Code extract XMLOPCWriteManagement.Write

Description

An array ("theItems()") of the type "Item" with items and their values is transferred to the "Write" method. Here, "Item" is a structure which was defined within this class. The items of the Item() array must be transferred into the "m_ItemRequestList" list of the type "WriteRequestItemList".

V1.0

26.04.05

59/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Executing the write operation


Table 4-8

Description Position Code extract XMLOPCWriteManagement.Write

Description

The "m_ItemRequestList" list contains the items (item names and the values to be written) and it will be transferred to the "Write" method. "True" specifies that the new current values of the process variables are to be returned after writing. "m_ItemReplyList" of the type "ReplyItemList" contains the returned items with their new values.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

The "Write" method


Table 4-9

Parameter Options As RequestOptions ItemList As WriteRequestItemList ReturnValuesOnReply As Boolean RItemList As ReplyItemList Errors() As OPCError

Value m_RequestOptions m_ItemRequest List True M_ItemReplyList m_OPCErrors

Description Contains specific options for the Write method Contains the items to be written (item names and values to be written) The new current values of the process variables should be returned after writing. Contains the returned items with their new values. Array with the possibly occurring errors.

V1.0

26.04.05

60/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Transferring returned values


Table 4-10

Description Position Code extract XMLOPCWriteManagement.ValueChanges

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description

The items returned by the "Write" method are transferred to the "ValueChanges" function and are read from there. The returned values are transferred via the DataUpdated event. The items in the "SubArgs" argument of the type "OPCCallbackEventArgs" are transferred to the DataUpdated event. The "OPCCallbackEventArgs" class is a class created by the user. It can be derived from the .NET-Klasse "EventArgs" and contains an additional item array (see following figure). This item array contains the item values returned from the OPC server.

V1.0

26.04.05

61/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Adopting returned values


Table 4-11

Description Position Code extract MainForm.m_XMLOPCWriteSetpoints_DataUpdated

Description
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

The Sub "m_XMLOPCWriteSetpoints_DataUpdated" is logged on at the "DataUpdated" event of the "m_XMLOPCWriteSetpoints" class with the keyword "Handles". When triggering the event (see previous section), then this sub is called. The argument "e" contains the transferred items.

4.3.3 Overview

Using Subscriptions

This chapter explains how the subscription is used in this application. The use of subscriptions is thereby entirely encapsulated in the XMLOPCSubscriptionManagement class. The following table shows the steps for using a subscription with the mentioned class. The detailed explanation of the steps occurs in the next sections of this chapter.
Table 4-12

Step Collecting items in an item list Logging on a subscription

Explanation The process variables which are to be polled cyclically with the subscription, are collected into an item list. Here the subscription is logged on at the web service. Thereby, the item list is also transferred to the web service. After the subscription was logged on at the web service, the service returns the current process values to the subscription.

Reading the returned values

V1.0

26.04.05

62/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Cyclic polling of a subscription (Request)

The cyclic polling is timer controlled. After the subscription was logged on, the timer is automatically started. The time interval of the timer is defined in the options dialog of the Windows application. If the timer has elapsed, it is stopped and the polled refresh for the subscription is triggered (asynchronously). When the polling of the subscription has ended, the values transferred by the web service are read and transferred to the super-ordinate class via an event. At the same time, the timer is restarted. If the cyclic refreshing of the process value is to be terminated, the timer which triggers the cyclic polling of the subscription must be switched off, and the subscription be logged off at the web service. Note If the subscription is not polled over a period of time specified during logon, the web service cancels the subscription by itself. The client does not receive any notification. If the client tries to poll the subscription once more, he receives an error message.

Cyclic polling of a subscription (Response)

Logging off the subscription

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

63/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Collecting items in an item list


Table 4-13

Description Position Code extract XMLOPCSubscriptionManagement.AddItems

Description
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

A ("theItems()") array of the type "Item" with items (contain only the item name, i.e. the symbolism of the OPC items) is transferred to the "AddItems" method. Here, "Item" is a structure which was defined in this class. The items of the Item() array must first be transferred into the "m_ItemRequestList" list of the type " SubscribeRequestItemList".

Logging on the subscription


Table 4-14

Description Position Code extract XMLOPCSubscriptionManagement.Subscribe

Description

The subscription is logged on at the web service using the "Subscribe" method of the web service reference "m_OPCServer" (of the "OPCXML_DataAccess" type). After the subscription was logged on, a timer is started (not displayed in the screenshot). When the timer has elapsed the subscription is polled.

V1.0

26.04.05

64/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

The "Subscribe" method


Table 4-15

Parameter Options As RequestOptions ItemList As SubscribeRequestItemList ReturnValuesOnReply As Boolean SubscriptionPingRate As Integer

Value m_Subscription Options m_ItemRequest List True UpdateRate * 5

Description Contains additional options for the subscription (e.g. in this application, the time stamp of the OPC items is to be reported back by the server). Contains the symbolic names of the OPC items which are to be contained in this subscription. The current values of the process variables are to be returned for this call. Time out interval for the subscription. Unless the subscription is polled within this time, the web service cancels the subscription and releases the reserved resources. The client is not notified of this. In this application, the timeout interval has five times the value of the update time of the subscription (defined in the options dialog of the application). Contains the items returned from the web service with their actual values This is an array which contains the possibly occurring errors. The ServerHandle returned from the web service via which this subscription is identified.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

RItemList As SubscribeReplyItemList Errors() As OPCError ServerSubHandle As String

ItemReplyList m_OPCErrors m_OPCServerHandles(0)

Reading the returned values


Table 4-16

Description Position Code extract XMLOPCSubscriptionManagement.Subscribe

Description

The items of "ItemReplyList" returned by the "Subscribe" method are transferred via an event, like in the "Write" method of the "XMLOPCWriteManagement" class.

V1.0

26.04.05

65/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Cyclic polling of a subscription (Request)


Table 4-17

Description Position Code extract XMLOPCSubscriptionManagement.Refresh

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description

After the timer "m_UpdateTimer" has elapsed, the "Refresh" function is called. In this function the timer is deactivated first. Then the "BeginSubscriptionPolledRefresh" method is called. This triggers the asynchronous polling of the subscription.

The "BeginSubscriptionPolledRefresh" method


Table 4-18

Parameter Options As RequestOptions ServerSubHandles() As String HoldTime As Date HoldTimeSpecified As Boolean WaitTime As Integer ReturnAllItems As Boolean callback As System.AsyncCallback

Value m_Subscription Options m_OPCServerHandles CDate("0:00:00") False 0 False New AsyncCallback( AddressOf SubscriptionCa llBack) m_OPCServer

Description Contains additional options for the subscription (e.g. in this application, the time stamp of the OPC items is to be returned from the server). String array which contains the ServerHandle of the subscription to be polled. Helps to poll several subscriptions simultaneously. Is not used here. See \3\ The parameter "HoldTime" should not be used. Is not used here. See \4\ Only those items are to be returned whose value has changed since the last polled refresh. Transferring the callback function (here "SubscriptionCallBack "), which is called when the asynchronous polling of the subscription has ended.

asyncState As Object

Reference to the web server object from which the asynchronous function is called. This is transferred to the callback function.

V1.0

26.04.05

66/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Cyclic polling of a subscription (Response)


Table 4-19

Description Position Code extract XMLOPCSubscriptionManagement.SubscriptionCallBack

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description

The "SubscriptionCallBack" function is called after the asynchronous polling of the subscription has ended. The "ar" object contains a reference to the web service which is assigned to the "OPCProxy" object. The "OPCProxy" object can then be used to poll the refreshed values of the subscription. This occurs using the "EndSubscriptionPolledRefresh()" function which is described below.

The " EndSubscriptionPolledRefresh" method


Table 4-20

Parameter asyncResult As System.IAsyncResult ar

Value

Description Represents the status of an asynchronous process. Contains the "AsyncState" property, which in return contains a reference to the web service object which was transferred with the "BeginSubscriptionPolledRefresh" function. Contains the ServerHandles of the subscriptions which could not be processed by the web service. Contains the item lists of all subscriptions which were polled. In this application only one subscription is polled. If errors have occurred during polling the subscriptions, they are entered here. If the value of this attribute is TRUE, changes have occurred for the items which could not be saved due to the restricted resources. The individual items indicate whether they are affected from the resource restriction or not.

InvalidServerSubHan dles() As String RItemList() As SubscribePolledRefreshReplyItemList Errors() As OPCError DataBufferOverflow As Boolean

InvalidHandles

ItemPolledRefresh List

OPCErrors Overflow

V1.0

26.04.05

67/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Logging off the subscription


Table 4-21

Description Position Code extract Description The subscription listed here is logged off. The web service can now release the resources reserved for this subscription. The specified ServerHandle is in this application saved in the instance of the class as a member variable. XMLOPCSubscriptionManagement.CancelSubscription

The " SubscriptionCancel " method


Table 4-22

Parameter
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Value ServerHandle m_Subscription Options.ClientRequestHandle

Description Used for identifying the subscription in the server. Optional specifying of the ClientHandle. Used for identifying the subscription on the client side.

ServerSubHandle As String ClientRequestHandle As String

4.4
4.4.1

ASP.NET application
Connecting to the OPC server

Introduction The entire functionality for the server management (connecting and disconnecting the OPC server) is encapsulated in the "XMLOPCServerManagement" class. The most important code sections of this class are discussed in greater detail below. The class is used in the Windows application as well as in the ASP.NET application. However, there are some small, architecture related differences between both applications. These differences do not relate directly to using the OPC XML-DA interface and are not discussed here in greater detail (see source code of the application).

V1.0

26.04.05

68/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Verifying the availability of the web service


Table 4-23

Description Position Code extract XMLOPCServerManagement.ServerConnect

Description

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

The "OPCRequest" object establishes a connection with the web server. The address of the web server is transmitted to the object ("m_ServerName"). The "GetResponse" function requests a response from the web service. The response itself is not important. If no connection can be established, no error occurs and the program can be continued. In case of an error, an exception is thrown, which is discussed in the next section.

Transferring credentials to the web service (authentication)


Table 4-24

Description Position Code extract XMLOPCServerManagement.ServerConnect

Description

If an authentication for the web service is required, the GetResponse method described in the previous section throws an exception (this also means that the connection to the web service could be established successfully). This exception is of the type "WebException" and has the state "ProtocolError". The "m_OPCDataAccess" object is of the type "OPCXML_DataAccess" and represents an instance on the web service. The property "Credentials" of the "System.Net.ICredentials" type contains the authentication information for the web service. The "DefaultCredentials" transferred here is the logon information of the user (user name and password) under which the ASP.NET application runs on the head-end. This user must be authorized to access the web service (see 2.9 Safety settings of an ASP.NET application)

V1.0

26.04.05

69/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Verifying the operating status of the OPC server


Table 4-25

Description Position Code extract XMLOPCServerManagement.ServerConnect

Description

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

After the accessibility of the web service has been verified, and necessary logon information transferred, the operating status of the OPC server is verified. First the address of the web service is transferred to the "Url" property of the "m_OPCDataAccess" object. The method "GetStatus" verifies the operating status of the OPC server. "m_OPCReply" contains the response of the web service.

The "GetStatus" method


Table 4-26

Parameter LocaleID As String ClientRequestHandle As String Status As Server Status en "1"

Value

Description Optional attribute used by the client to define the language for certain returned data. Optional and in this example user-definable. In complex systems, this detail helps the client allocating requests and responses. Contains the status information on the OPC server, such as version, producer, etc..

"m_OPCStatus"

4.4.2

Writing process values (analog reading)

Introduction The entire functionality for writing process values into the controller is encapsulated in the "XMLOPCWriteManagement" class. This class is also used in both applications of this application example. The existing differences in the class are documented in the source code of the respective application.

V1.0

26.04.05

70/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Collecting items in an item list


Table 4-27

Description Position Code extract XMLOPCWriteManagement.Write

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description

An array ("theItems()") of the type "Item" with items and their values is transferred to the "Write" method. Here, "Item" is a structure which was defined within this class. The items of the Item() array must first be transferred into the "m_ItemRequestList" list of the type " WriteRequestItemList".

Executing the write operation


Table 4-28

Description Position Code extract XMLOPCWriteManagement.Write

Description

The "m_ItemRequestList" list contains the items (item names and the values to be written) and it will be transferred to the "Write" method. "True" specifies that the new current values of the process variables are to be returned after writing. "m_ItemReplyList" of the type "ReplyItemList" contains the returned items with their new values.

V1.0

26.04.05

71/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

The "Write" method


Table 4-29

Parameter Options As RequestOptions ItemList As WriteRequestItemList ReturnValuesOnReply As Boolean RItemList As ReplyItemList Errors() As OPCError

Value m_RequestOptions m_ItemRequest List True m_ItemReplyList m_OPCErrors

Description Contains specific options for the Write method Contains the items to be written (item names and values to be written) The new current values of the process variables should be returned after writing. Contains the returned items with their new values. Array with the possibly occurring errors.

Transferring returned values


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Table 4-30

Description Position Code extract XMLOPCWriteManagement.Write

Description

The items returned by the "Write" method are located in the "m_ItemReplyList". In the "For"-loop, all returned items are now written into an array of items ("tempItems()") and returned to the caller of the "Write" method.

V1.0

26.04.05

72/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

4.4.3 Overview

Using Subscriptions

This chapter explains how the subscription is used in this application. The use of subscriptions is thereby entirely encapsulated in the XMLOPCSubscriptionManagement class. The following table shows the steps for using a subscription with the mentioned class. The detailed explanation of the steps occurs in the next sections of this chapter.
Table 4-31

Step Collecting items in an item list Logging on a subscription

Explanation The process variables, which are to be polled cyclically with the subscription, are collected into an item list. Here the subscription is logged on at the web service. Thereby, the item list is also transferred to the web service. After the subscription was logged on at the web service, the service returns the current process values to the subscription. The cyclic polling is timer controlled. After a subscription was logged on, a timer is started on the client with a Java script. The time interval of the timer is defined in the user interface of the ASP.NET application. As soon as the timer has elapsed, a refreshing of the page, hence a polled request of the subscription, is triggered by the Java script. As soon as the polled request of the subscription has terminated, the values transferred by the web service are read and written to the user interface. If the cyclic refreshing of the process value is to be terminated, the timer which triggers the cyclic polling of the subscription must be switched off, and the subscription be logged off at the web service.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Reading the returned values

Cyclic polling of a subscription (Client side)

Cyclic polling of a subscription (Server side)

Logging off the subscription

V1.0

26.04.05

73/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Collecting items in an item list


Table 4-32

Description Position Code extract XMLOPCSubscriptionManagement.AddItems

Description
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

A ("theItems()") array of the type "Item" with items (contain only the item name, i.e. the symbolism of the OPC items) is transferred to the "AddItems" method. Here, "Item" is a structure which was defined within this class. The items of the Item() array must first be transferred into the "m_ItemRequestList" list of the type " SubscribeRequestItemList".

Logging on a subscription
Table 4-33

Description Position Code extract XMLOPCSubscriptionManagement.Subscribe

Description

The subscription is logged on at the web service using the "Subscribe" method of the web service reference "m_OPCServer" (of the "OPCXML_DataAccess" type). In this application, the returned ServerHandle is saved in a session variable: Session("ServerHandle"), this is not depicted in the above code.

V1.0

26.04.05

74/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

The "Subscribe" method


Table 4-34

Parameter Options As RequestOptions ItemList As SubscribeRequestItemList ReturnValuesOnReply As Boolean SubscriptionPingRate As Integer

Value m_Subscription Options m_ItemRequest List False UpdateRate * 5

Description Contains additional options for the subscription (e.g. in this application, the time stamp of the OPC items is to be reported back by the server). Contains the symbolic names of the OPC items which are to be contained in this subscription. The current values of the process variables are not to be returned for this call. Time out interval for the subscription. Unless the subscription is polled within this time, the web service can cancel the subscription and release the reserved resources. Is not important for this call, as the actual values are not to be returned. This is an array which contains the possibly occurring errors. The ServerHandle returned from the web service via which this subscription is identified.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

RItemList As SubscribeReplyItemList Errors() As OPCError ServerSubHandle As String

ItemReplyList m_OPCErrors m_OPCServerHandles(0)

V1.0

26.04.05

75/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Cyclic polling of a subscription (Client side)


Table 4-35

Description Position Code extract Java script on the ASPX page in the element: "<script language="javascript" id="clientEventHandlersJS">"

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Description

The Java script function "window_onload" is called at each loading or refreshing of the page. In the "enableInterval" function, a timer is started or stopped depending on the status of the "chkAutoRefresh" checkbox. The checkbox is activated when connecting to the OPC server. If the timer is started ("timer = window.setInterval..."), the function "clickIt" is called respectively after the "interval" time has elapsed. This in return triggers a click event to the "btnRefresh" button. This button has no server sided code, but triggers the execution of the "Page_Load" sub and hence the polling of the subscription.

V1.0

26.04.05

76/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Cyclic polling of a subscription (Server side)


Table 4-36

Description Position Code extract XMLOPCSubscriptionManagement.Refresh

Description
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

The "Refresh" method of the "XMLOPCSubscriptionManagement" class is called in the "Page_Load" method of the ASPX page (i.e. for each refreshing of the page). The "SubscriptionPolledRefresh" function is used for polling a subscription.

The "SubscriptionPolledRefresh" method


Table 4-37

Parameter Options As RequestOptions ServerSubHandles() As String

Value m_Subscription Options tempServerHandles

Description Contains additional options for the subscription (e.g. in this application, the time stamp of the OPC items is to be reported back by the server). String array which contains the ServerHandle of the subscription to be polled. Helps to poll several subscriptions simultaneously. The ServerHandle used here was previously taken from the session variable: Session("ServerHandle"). Is not used here. See \3\ The parameter "HoldTime" should not be used. Is not used here. See \3\ Only those items are to be returned whose value has changed since the last polled refresh. String array into which the server enters invalid ServerHandles. Array of ItemLists, which contain the items returned by the server This is an array which contains the possibly occurring errors.

HoldTime As Date HoldTimeSpecified As Boolean WaitTime As Integer ReturnAllItems As Boolean ServerSubHandles() As String RItemList() As SubscribePolledRefreshReplyItemList Errors() As OPCError

CDate("0:00:00") False 0 False tempInvalidSH ReplyList

OPCErrors

V1.0

26.04.05

77/93

Function Principles and Program Structures Explanations on the Example Program


Data Exchange via XML-DA Entry-ID: 21402169

Parameter DataBufferOverflow As Boolean

Value Overflow

Description If the value of this attribute is TRUE, changes have occurred for the items which could not be saved due to the restricted resources. The individual items indicate whether they are affected by the resource restriction or not.

Logging off a subscription


Table 4-38

Description Position Code extract Description


Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

XMLOPCSubscriptionManagement.CancelSubscription

The subscription listed here is logged off. The web service can now release the resources reserved for this subscription.

The " SubscriptionCancel " method


Table 4-39

Parameter ServerSubHandle As String ClientRequestHandle As String

Value ServerHandle m_Subscription Options.ClientRequestHandle

Description Used for identifying the subscription within the server. Optional specifying of the ClientHandle. Used for identifying the subscription on the client side.

V1.0

26.04.05

78/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

Configuration
the configuration steps and tools used for creating this application. The following descriptions are intended as a more detailed explanation and need not necessarily be executed. The configuration steps required for demonstrating the application are explained in greater detail in the "Demonstration" part of this application.

Here you will find information on

5.1

Configuration of an OPC Server with STEP 7


The configuration of the OPC server is performed with STEP 7. Firstly, this includes the configuration of the S7 communication between the head-end, on which the OPC server runs, to the automation station. Secondly, the access protection for individual process variables is also set in STEP 7.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Example configuration The following configuration sequences have already been executed in the delivered STEP 7 example project (archived in the included file "21402169_OPC_XML-DA_STEP7_v10.zip"). If you wish to use this example project, you can skip this chapter. The following configuration steps are only required in a new STEP 7 project. Creating an OPC-Servers in a SIMATIC PC station The prerequisite for executing the following configuration steps is a STEP 7 project opened in the SIMATIC Manager. This project should already contain a configured S7-300 or S7-400 station. This S7 station must also contain an S7-capable module (CPU or CP, PROFIBUS or Industrial Ethernet). Below, an Industrial Ethernet subnet is used for the communication. The configuration for PROFIBUS occurs analog to this.
Table 5-1

No. 1.

Instructions Create a SIMATIC PCStation in the STEP 7 project and enter a unique name for it. This PC station represents the head-end on which the OPC will be running.

Note

V1.0

26.04.05

79/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

No. 2.

Instructions Open the configuration of the PC station in HW Config (Select the PC station and double-click on Configuration).

Note

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

3.

Enter an OPC Server selected from the hardware catalog into the PC station. Please ensure, that the version of the OPC server matches that of the SIMATIC NET version installed on the head-end.

V1.0

26.04.05

80/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

No. 4.

Instructions Enter the communication module from the hardware catalog, used in the headend, into the PC station. In this application, the Ethernet interface integrated in the head-end is used. Therefore, an IE General module is added. Please ensure that the correct SIMATIC NET version is used here.

Note

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

5.

In the properties dialog of the Ethernet interface you first set the current IP address as well as the Subnet mask. In the field Subnet you select the network via which the head-end is connected with the S7 station. Note The IP address of the headend must be located in the same subnet as the IP address of the S7 station.

6.

Save and compile the hardware configuration and close the HW Config Editor.

Configuring an S7 connection to the OPC server The communication between the OPC server and the S7 station in this application is to be provided with an S7 connection. This connection must be configured with the "NetPro" tool. This configuration has already been performed in the attached STEP 7 example project "315_OPC" (archived in the included file "21402169_OPC_XML-DA_STEP7_v10.zip").

V1.0

26.04.05

81/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

Table 5-2

No. 1.

Instructions Open the "NetPro" tool from the SIMATIC Manager via the button in the toolbar.

Note

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

2.

Select the OPC server in the head-end and insert a new connection via the context menu.

V1.0

26.04.05

82/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

No. 3.

Instructions Select the target CPU in the Insert New Connection dialog window (in this example the CPU 315-2 DP). Select the connection type S7 connection. Confirm the entry with OK. The connection properties displayed in the following dialog can be used unchanged.

Note

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

4.

In order to activate the symbolic access to the process variables of the S7 station, please open the Object Properties of the OPC server.

V1.0

26.04.05

83/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

No. 5.

Instructions Select the S7 tab in the Properties dialog (as the S7 is being used). In the Use symbols area you select All in order to access all symbols of the S7 program of the controller. Confirm the entry with OK. Note In the field Cycle time you can specify the update rate of the OPC server. For this application it is also the maximum update time of a subscription.

Note

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

6.

Save and compile the configuration and load it into PC station and S7 controller.

5.2

Configuration of the Internet Information Services

Creating a virtual directory or an application The access to the data and applications of an IIS web server occurs via the virtual directories (see 2.1 Internet Information Services (IIS)). For creating a virtual directory or an application please perform the following steps.
Table 5-3

No. 1.

Instructions Open the Internet Information Services with: Start Control Panel Administrative Tools Internet Services Manager Note If the "Administrative Tools" item is not available, select: Start Run... and enter the following string: %SystemRoot%\System32\Inetsrv\iis.msc

Note

V1.0

26.04.05

84/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

No. 2.

Instructions Select Default Web Site from the context menu of this folder (click with the right mouse button) and select New Virtual Directory Click the "Virtual Directory Creation Wizard" and then the Next button. In the field Alias: you enter a name for the virtual directory and then click the Next button. Note Please ensure that the name does not contain any special characters or dots. The access to such virtual directories will be blocked later on (using the "IISLockdown" tool).

Note

3. 4.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

5.

Use the Browse... button to select a directory on your PC that contains the data which the virtual directory should contain. Press Next> to confirm your selection. Checkmark the following items in the Access Permissions dialog box: Read Run scripts(such as ASP) (if the virtual directory should be an application) Press Next> to confirm your selection. Click Finish to close the Virtual Directory Creation Wizard. In the Default Web Site entry, the new virtual directory should now be visible.

6.

7.

8.

Close the configuration window.

V1.0

26.04.05

85/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

Adjusting web permissions and user settings For changing web permissions for a website, a virtual directory, an application, or an individual file, please perform the following steps.
Table 5-4

No. 1.

Instructions Start the Internet Information Services manager with: Start Settings Control Panel Administrative Tools Internet Services Manager In the left tree you navigate to the desired object (website, virtual directory etc.) Open the Properties dialog via the context menu of the entry (right mouse click) and selecting the Properties dialog. There you change to one of the following tabs, depending on the object you have selected: Home Directory for a website (Virtual) Directory for a virtual directory or application File for a file

Note

2. 3.

4.
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

5. 6.

In this tab you specify the corresponding web permissions and user settings for the selected object. Confirm the entry with OK and close the configuration console.

See 2.2 Safety aspects of the Internet Information Services.

Deactivating the Anonymous access to the web server The anonymous access to the web server, a certain virtual directory, or a file, is controlled via the Internet Information Services manager. In order to deactivate the anonymous access for the entire web server please perform the following steps. The settings for an individual directory or a file occurs analog.
Note

The Anonymous access to the entire web server is deactivated automatically by the IISLockdown tool

V1.0

26.04.05

86/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

Table 5-5

No. 1.

Instructions Start the Internet Information Services manager with: Start Settings Control Panel Administrative Tools Internet Services Manager In the left tree you navigate to the entry [PC name] (local computer) Websites. Open the Properties dialog via the context menu of the entry (right mouse click) and selecting the Properties dialog. Select the Directory Security tab and in the Anonymous access and authentication control area you press the Edit button.

Note

2. 3.

This folder contains all websites of the web server

4.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

5.

Remove the checkmark for Anonymous access. Please ensure that in the Authenticated access area either Basic authentication or Integrated Windows authentication has been selected as otherwise no access at all will be permitted to the web server.

6.

Close all dialog boxes by clicking OK.

Setting the authentication method For the IIS under Windows XP you can chose between the authentication methods Basic authentication and Integrated Windows authentication (see 2.2 Safety aspects of the Internet Information Services). For setting this authentication method please perform the following steps.
Note

In this application, the integrated Windows authentication is used.

V1.0

26.04.05

87/93

Function Principles and Program Structures Configuration


Data Exchange via XML-DA Entry-ID: 21402169

Table 5-6

No. 1.

Instructions Start the Internet Information Services manager with: Start Settings Control Panel Administrative Tools Internet Services Manager In the left tree you navigate to the entry [PC name] (local computer) Websites. Open the Properties dialog via the context menu of the entry (right mouse click) and selecting the Properties dialog. Select the Directory Security tab and in the Anonymous access and authentication control area you press the Edit button.

Note

2. 3.

This folder contains all websites of the web server

4.

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

5.

In the Authenticated access area you can checkmark the authentication method to be used.

6.

Close all dialog boxes by clicking OK.

V1.0

26.04.05

88/93

Appendix and List of Further Literature Configuration


Data Exchange via XML-DA Entry-ID: 21402169

Appendix and List of Further Literature

Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

V1.0

26.04.05

89/93

Appendix and List of Further Literature Glossary


Data Exchange via XML-DA Entry-ID: 21402169

Glossary
The following explanations and definitions were taken from the Internet encyclopedia "Wikipedia", see \5\.

ACL Access Control List. Used by the operating system and the applications in order to check which user has access to which services (files, network services). ACLs allow very fine adjustment. Authentication Authentication refers to the process of verifying the identity of a person or a program based on certain features. This can, for example, occur by means of a finger print, a certain user name and password, or any other legitimating.
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Authorization Refers to the assignment and verification of access rights to data and services of a system by a user. Authorization mainly occurs after successful authentication. Cookie A Cookie (actually HTTP cookie) is a text file and contains information (e.g. session information), which a server sends to a client web browser. The cookie is returned to the server each time the client accesses the server. HTTP The Hypertext Transfer Protocol (HTTP) is a stateless data exchange protocol for transfer of data. It is one of the protocols provided by the TCP/IP protocol stack. Primarily it is used within the framework of the world wide web for transferring web-sites. HTML The Hypertext Markup Language (HTML) is a document format for marking hyper text in the World Wide Web. ISAPI filter ISAPI filters latch in to the data traffic of a web server or proxy. This enables them to read and change all transferred data. Namespace A name identifies an object. Unique allocation of the object requires taking into account the respective context space or name space.

V1.0

26.04.05

90/93

Appendix and List of Further Literature Glossary


Data Exchange via XML-DA Entry-ID: 21402169

NTFS NTFS means New Technology File System and is the file system of Windows NT, including its successor Windows 2000 and Windows XP. SSL SSL (Secure Sockets Layer) refers to a transfer protocol which enables encoded communication using tunneling. TCP/IP Transmission Control Protocol / Internet Protocol. The internet protocol suite is a family of network protocols which form the basis for network communication in the internet. URL
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

Uniform Resource Locator (URL) refers to a standardized addressing format for resources in computer networks. WWW The World Wide Web (abbrev. WWW) is a hypertext system which can be called up via the Internet.

V1.0

26.04.05

91/93

Appendix and List of Further Literature Literature


Data Exchange via XML-DA Entry-ID: 21402169

7
7.1

Literature
Bibliographic References
This list is by no means exhaustive and only gives a selection of appropriate sources.
Table 7-1

Topic /1/ STEP 7

Title Automatisieren mit STEP 7 in AWL und SCL (Automating with STEP7 in STL and SCL) Hans Berger published by: Publicis MCD Verlag ISBN 3-89578-113-4 SIMATIC NET, Industrielle Kommunikation mit PG/PC Band 1 Grundlagen, Systemhandbuch (SIMATIC NET, Industrial Communication with PG/PC volume 1 Basics, System Manual) (on SIMATIC NET CD) SIMATIC NET, Industrielle Kommunikation mit PG/PC Band 2 Schnittstellen, Systemhandbuch (SIMATIC NET, Industrial Communication with PG/PC volume 1 Basics, System Manual) (on SIMATIC NET CD) ASP.NET Grundlagen und Profiwissen, Webserverprogrammierung und XML Webservices im .NET Framework (ASP.NET Basics and Professional knowledge, Web Server programming and XML Web Services in .NET Framework) Patrick A. Lorenz Carl Hanser Verlag ISBN 3-446-22552-8

/2/
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

SIMATIC NET, Industrial communication

/3/

SIMATIC NET, Industrial communication

/4/

ASP.NET

7.2

Internet links
This list is by no means exhaustive and only gives a selection of appropriate sources.
Table 7-2

Topic \1\ \2\ \3\ Reference to the documentation Siemens A&D Customer Support Online documentation of the IIS

Title http://support.automation.siemens.com/WW/view/ en/21402169 http://support.automation.siemens.com http://www.microsoft.com/windows2000/en/server/i is/default.asp

V1.0

26.04.05

92/93

Appendix and List of Further Literature Literature


Data Exchange via XML-DA Entry-ID: 21402169

Topic \4\ IIS authentication

Title http://msdn.microsoft.com/library/default.asp?url=/l ibrary/enus/vsent7/html/vxconiisauthentication.asp http://en.wikipedia.org/ http://www.w3c.de/Misc/XML-in-10-points.html http://weblogs.cs.cornell.edu/AllThingsDistributed/ archives/000120.html http://www.microsoft.com/technet/security/current. aspx http://www.mono-project.com/

\5\ \6\ \7\ \8\ \9\

Online encyclopedia XML Basics Explanation on web service Microsoft security updates .NET implementation on UNIX Safety for ASP.NET applications Check list for secure web servers Introduction into ASP.NET (German only)

\10\
Copyright Siemens AG 2005 All rights reserved 21402169_OPC_XML-DA_Extension_DOKU_ v10_e.doc

http://msdn.microsoft.com/library/default.asp?url=/l ibrary/en-us/dnnetsec/html/secnetlpMSDN.asp http://msdn.microsoft.com/library/default.asp?url=/l ibrary/en-us/secmod/html/secmod104.asp http://www.galileocomputing.de/openbook/asp/

\11\ \12\

V1.0

26.04.05

93/93

S-ar putea să vă placă și