![]() |
Home | Documentation |
The CURL plugin
updated Mon Feb 12 2018 by Robert van Engelen
|
The CURL plugin for gSOAP provides a bridge for the gSOAP engine to use libcurl for internet communications. While gSOAP provides a full HTTP stack, libcurl can be used to support additional protocols and features by replacing gSOAP's HTTP stack.
To use the CURL plugin:
#include "plugin/curlapi.h"
to your client-side code and compile your code together with plugin/curlapi.c
. Link your code with libcurl.curl_global_init(CURL_GLOBAL_ALL)
at the start of your program to initialize CURL. Add curl_global_cleanup()
at the end of your program.soap
context, register the plugin with this soap
context, Or use the soap
member of a soapcpp2-generated C++ proxy class. Use soap_register_plugin(soap, soap_curl)
to register.CURL *curl
handle already set up, then register the plugin with soap_register_plugin_arg(soap, soap_curl, curl)
. The benefit of this is that you can set CURL options of the handle. Do not delete this handle until the soap
context is deleted.The plugin is not limited to SOAP calls, you can use it with XML REST and JSON in gSOAP. The plugin registry steps are the same for any client-side API service calls.
The CURL plugin supports SOAP with MTOM attachments, including streaming MTOM. Other plugins can be combined with this plugin, such as WSSE for WS-Security.
To use the CURL plugin, register the plugin with the current soap
context using soap_register_plugin(soap, soap_curl)
. This also creates a new CURL handle that is internally used by the plugin until the soap
context is deleted. For C++ proxy classes generated with soapcpp2, register the plugin with the soap
member of the proxy class.
The gSOAP HTTP chunked transfer mode and timeout settings are also used by the CURL plugin, when set, as follows:
When an transmission error occurs, use soap_curl_reset(soap)
to reset the plugin. This ensures that the gSOAP IO operations are reset and will behave again normally.
Alternatively, you can create your own CURL *curl
handle, configure it, and pass it to the plugin as follows:
Note that C++ proxy classes generated by soapcpp2 with option -j
have a soap
member that should be used to register the plugin with:
This example shows a calculator client application with CURL and gSOAP.
The soapcpp2 command is applied to calc.h
with soapcpp2 -c -CL calc.h
, where calc.h
is:
This generates soapStub.h
, soapH.h
, soapC.c
, soapClient.c
, and calc.nsmap
.
To keep this example small, the main program uses the calculator service to add two values:
We compile this example program together with stdsoap2.c
, soapC.c
, soapClient.c
, plugin/curlapi.c
and we link it with libcurl.
As stated previously, to use a current CURL *curl
handle that you have created, use soap_register_plugin_arg(soap, soap_curl, curl)
to register the plugin.
See the gSOAP JSON documentation for details about using JSON with gSOAP in C and in C++.
A JSON client in C with CURL has the following outline:
As stated previously, to use a current CURL *curl
handle that you have created, use soap_register_plugin_arg(soap, soap_curl, curl)
to register the plugin.
JSON in C++ is similar to the C example shown with the benefit of the easy-to-use JSON C++ API.