I am using gsoap to access a web service. I generate the code with wsdl2h and soapcpp2 in the following way:
wsdl2h -o BILBO.h http://www.bilbao.eus/WebServicesBilbao/services/ws_bilbaoSOAP?wsdl
soapcpp2 -j -r -CL -1 BILBO.h
And accessing the service in the following way:
#include "soapws_USCOREbilbaoSOAPSoapBindingProxy.h"
#include "ws_USCOREbilbaoSOAPSoapBinding.nsmap"
int main()
{
ws_USCOREbilbaoSOAPSoapBindingProxy service;
char str_buf[128];
const char *servicio = "BUSLISPARO";
const char *usuario = "BILBOBUS";
int cod_linea = 30;
sprintf(str_buf, "<![CDATA[<PETICION><CODIGOLINEA>%d</CODIGOLINEA></PETICION>]]>", cod_linea);
std::string parametros(str_buf);
_ns1__wsBilbao param_req;
param_req.servicio = (char *)servicio;
param_req.usuario = (char *)usuario;
param_req.parametros.push_back(parametros);
if (service.send_wsBilbao(NULL, NULL, ¶m_req) != SOAP_OK)
{
service.soap_sprint_fault(str_buf, sizeof(str_buf));
service.destroy(); // delete data and release memory
printf("err: %s\n", str_buf);
return -1;
}
_ns1__wsBilbaoResponse param_resp;
if (service.recv_wsBilbao(param_resp) != SOAP_OK)
{
service.soap_sprint_fault(str_buf, sizeof(str_buf));
service.destroy(); // delete data and release memory
printf("err: %s\n", str_buf);
return -1;
}
for (int i = 0; i < param_resp.valores.size(); i++)
{
printf("[%d] \"%s\"\n", i, param_resp.valores[i].c_str());
}
service.destroy(); // delete data and release memory
}
My problem is that when I run the code I get the following output:
[0] ""
I expect to get some data. When I preform the same request with Soap UI I do get it.
Comparing the differences between the Soap UI requests and the gsoap requests I notice gsoap is escaping < and > characters. In the following way:
<![CDATA[<PETICION><CODIGOLINEA>30</CODIGOLINEA></PETICION>]]>
Is there a way to tell gsoap no to escape < to < and > to >?
To send and receive plain XML you can use the _XML
built-in type that is a char*
string serialized "as-is", i.e. without translation. Then use the _XML
type at places where you used char*
in the header file for soapcpp2.
In C++ you can define typedef std::string XML;
in the header file for soapcpp2 to define an XML type that is serialized "as-is".
I don not fully understand why you are creating a string with <![CDATA[...
. You do not have to use CDATA when you are serializing strings, since gsoap serializes strings in valid XML.