ONVIF / gSOAP in C++ by example

October 21, 2016

onvif  soap  gsoap 

Retrieve a snapshot from an ONVIF complaint IP Camera using a client application written in C++.

If all you need is the code, head here.


Disclaimer

When I first started working with ONVIF and SOAP about a year ago, I was completely lost. I just couldn’t figure out where to start. I’m writing this post with the intention of providing other developers (who find themselves in a similar situation today that I was in a few months back) with a head-start. This post therefore, is NOT meant to be a complete tutorial.


ONVIF

ONVIF is a global and open industry forum. The ONVIF specification aims to achieve interoperability between network video products regardless of manufacturer. 1 ONVIF specifications are available in the form of WSDL XML (Web Services Description Language) files.

SOAP

SOAP (Simple Object Access Protocol) is a protocol specification for exchanging structured information in the implementation of web services in computer networks. It uses XML Information set for its message format.2 SOAP relies on HTTP (or SMTP) for transmission.

Now, just in case you were wondering what’s so simple about SOAP, rest assured you’re not alone.

gSOAP

So now, we have a specification (in the form of WSDL files) and we have the protocol (SOAP) for the server-client communication. All we need now is to translate these specs to code. Heres where gSOAP comes in.

gSOAP is a C and C++ software development toolkit for SOAP/XML web services and generic XML data bindings.3

Basically, gSOAP first translates the WSDL spec to a header file with the data binding interface. This is done by the wsdl2h tool. Then, the soapcpp2 tool runs a preprocessor on this header file and generates the data binding implementation with XML serializers to implement Web services and XML data bindings. The runtime engine handles HTTP and XML transport over any IO device and sockets and is responsible for memory allocation.4


Using gSOAP with ONVIF

For this topic, I couldn’t do a better job than what the folks at Genivia have already done on their website’s Developer Center. Their website is full of awesome resources on gSOAP, so please read about this there.


The example

In this example, I demonstrate how to retrieve a snapshot URI from an ONVIF complaint IP camera and download it locally. I’ve done all the wsdl2h and soapcpp2 stuff described above, just so you don’t have to do it.

The code is well commented and should be easy to read.

Prerequisites

You will need curl to build the app.

Usage

Clone the example code from github:

git clone https://github.com/Sufi-Al-Hussaini/onvif-gsoap-by-example

Now, all you have to do is:

cd onvif-by-example
make

Run the program:

./ipconvif -cIp '<camera-ip>' -cUsr '<camera-username>' -cPwd '<camera-password>'

Credits

The base code for this project was adapted from the gsoap-onvif github repo originally written by tonyhu.

References:

1. Wikipedia: ONVIF 2. Wikipedia: SOAP 3. Wikipedia: gSOAP 4. Genivia: gSOAP overview

Comments

comments powered by Disqus