![]() |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Writing hybrid applications using OPCData.NET Components and also consuming the OPC Web Client Web Service as a form of communications redundancy. This paper discusses how you can write an application that essentially uses both the OPCData.NET Components and the OPC Web Client Web Service in the same application. Because the OPCData.NET Components contain the same interface for both the COM and Web Service
components, you can very quickly and easily create an application that uses one tool to communicate to your OPC Server, and then in the event of a loss of communications switches over to the other component. For example: Pre-requisites If you are an OPC Web Client ActiveX Controls developer then this paper is not for you. This white-paper is specifically oriented towards the Visual Basic.NET or C# developers using the OPCData.NET Components and OPC Web Client Web Service. Some basic knowledge of the OPC Web Client and .NET technology/development is recommended, but not required. This paper will not discuss Microsoft .NET technology nor development strategies directly.
Common Interface The OPCData.NET Components make use of a common interface that allows you to write code for use with the OPC Web Client Web Service
or the main back-end engine which would allow you to communicate directly to the OPC Server via COM/DCOM. This common interface is going to be the key in which the application you create is going to be somewhat agnostic to the form of communications that currently in use. Step 1 - Defining the Interface You can define the interface within your .NET application as follows:
VB.NET Dim EasyDA As OPCLabs.EasyOPCDANet.IEasyDANet C# OPCLabs.EasyOPCDANet.IEasyDANet EasyDA; With the interface defined, you have not actually specified a component/object in which to use it with Step 2 - Defining the Transport (COM/DCOM or the Web Service) The interface simply allows us to access the properties/methods that are common between the components. We now need to specify which component we want to use: Using the COM/DCOM transport allowing your client-application to communicate directly to the OPC Server
VB.NET EasyDA = New OPCLabs.EasyOPCDANet.EasyDACOM C# EasyDA = New OPCLabs.EasyOPCDANet.EasyDACOM Using the Web Service:
VB.NET EasyDA = New OPCLabs.EasyOPCDANet.EasyDAWS(strURL) C# EasyDA = New OPCLabs.EasyOPCDANet.EasyDAWS(strURL) At this point, you can now start coding your OPC Client. The transport will be decided based on which component you used, i.e. . Step 3 - Determing when communications is lost Now that your communications is setup and your OPC Client applicaiton is reading/writing to/from the OPC
Server(s) you now need to implement a way in which you will be able to identify and react to when communications is distrupted. OPC Web Client Web Service If using the OPC Web Client Web Service then the following exception will be thrown upon trying to make a call to the Web Service: System.Net.WebException: When this particular exception is thrown, that will be your cue to switch to the alternate COM/DCOM transport via:
VB.NET EasyDA = New OPCLabs.EasyOPCDANet.EasyDACOM C# EasyDA = New OPCLabs.EasyOPCDANet.EasyDACOM OPCData.NET Components If using the OPCData.NET Components then the following exception will be thrown upon trying to make a call to OPC Web Client process: System.Runtime.InteropServices.COMException: or, System.Runtime.InteropServices.COMException: When such an exception is thrown, you can simply switch to the alternate Web Service transport via:
VB.NET EasyDA = New OPCLabs.EasyOPCDANet.EasyDAWS(strURL) C# EasyDA = New OPCLabs.EasyOPCDANet.EasyDAWS(strURL) A Note on Exceptions Due to the multitude of reasons why an OPC Server might become unavailable, you should expect to potentially see other exceptions too. Step 4 - Putting it all together Now that we have discussed this concept and looked at the specific objects to use, lets put together a simple application to demonstrate this concept.
Conclusion This paper has shown you how the OPC Web Client can in fact deliver a transport-redundancy ability within
your applications. This ability will allow you to create an application that is not dependant upon one form of transport and is easily/quickly able to adapt to situations by switching to an alternate transport. The example shown in this paper is very basic, and might not be the best way of using this functionality but
was shown as an easy way of accomplishing this ability. One suggestion might be to create your own class which consumes the OPC Web Client and handles this switch-over automatically so that your client-application
is truly unaware of the underlying transport. Downloads VB.NET Solution download - 65kb |
||||||||||||||||||||||||||||||||||||||
|
Copyright Software Toolbox, Inc., 1996-2004, All Rights Reserved Worldwide. |
||||||||||||||||||||||||||||||||||||||