With this article I want to show how to create a webservice in C# to communicate with an OPC-XML-DA server, like the one of SIMOTION D plc.
OPC-XML-DA is a communication protocol based on SOAP and XML.
To connect to a OPC-XML-DA server you need a WSDL file, that defines the procedures, arguments and data types.
OPC-XML-DA from is different from OPC-DA, because:
- XML-DA uses an xml serialization to send messages through HTTP, OPC-DA uses a binary efficient codification.
- Web services are connectionless and stateless, so you can’t create items and groups, or use callbacks like OPC-DA clients. You can use the subscription, but it’s far from the subscription that you have seen in OPC-DA clients. This subscritption is like an “intelligent polling”.
- You can’t browse for OPC servers like you did with OPC-DA. With XML-DA you need to know the IP address of the web service
An example of device that implements OPC-XML-DA server are the SIMOTION’S CPU family.
With this post i will show you how to create a webservice with Visual Studio and get started with OPC XML DA. Once you did this, there is plenty of resources in internet on how to do a polling to the plc.
How to get the wsdl file
To create a web service you need the wsdl file, and you will find this file on OPC Foundation website.
go to the OPC Foundation website, browse for OPC XML DA wsdl file, and save it with .wsdl extension.
After the update of OpcFoundation website, i couldn’t find the wsdl anymore.
So you should use wayback machine: http://web.archive.org/web/20120414093633/http://opcfoundation.org/webservices/XMLDA/1.0/
Remember to save the file with .wsdl extension, and not with .xml extension.
Create a web service in Visual Studio
Then to create a webservice in Visual Studio you should follow the next steps:
Siemens provided a document containing an explanation and sample code, check it out here.
I created a sample client based on the code provided by Siemens, you can download it from my github repository.