Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Example with KDSoap
I´m trying to make an example to learn to use KDSoap.
I´m using the http://www.dneonline.com/calculator.asmx to make test but i don´t know how to send the parameters.
It´s my code:
const QString endPoint = QLatin1String("http://dneonline.com/calculator.asmx"); const QString messageNamespace = QLatin1String("http://tempuri.org/"); KDSoapClientInterface client(endPoint, messageNamespace); KDSoapMessage message; message.addArgument(QLatin1String("intA"), 10); message.addArgument(QLatin1String("intB"), 5); KDSoapMessage response = client.call(QLatin1String("Add"), message);
But i dont receive the SUM 15, i always receive AddResult 0. I receive this xml:
respuesta : "<?xml version="1.0" encoding="UTF-8"?><n1:AddResponse xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n1="http://tempuri.org/">n1:AddResult 0</n1:AddResult></n1:AddResponse>\n"
i know i´m not sending the parameters in the right way, how can i do it?
Thanks in advance.
JonB last edited by JonB
<?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <Add xmlns="http://tempuri.org/"> <intA>int</intA> <intB>int</intB> </Add> </soap12:Body> </soap12:Envelope>
That's telling you that to call the method you need to produce
<Add ..> </Add>, inside which your parameters should be nested. I think your parameter passing code is probably correct, you are missing whatever from KDSoap to create an
Addnode at the top-level, and then make parameters children of that.
EDIT Whoops, no, I see,
client.call(QLatin1String("Add"), message);passes the
Add. And the response shows are getting an
AddResultback. Sorry! I'm having a rethink... :)
void KDSoapMessage::addArgument ( const QString & argumentName, const QVariant & argumentValue, const QString & typeNameSpace = QString(), const QString & typeName = QString() )
I'm not a C++-er, but that expects a
const QVariant & argumentValue. You pass a plain integer. Does that get correctly coerced from your literal integer constant? Are you supposed to create a
QVariantvariable holding an
intfor this to work, like
auto intA = QVariant::QVariant(10); message.addArgument(QLatin1String("intA"), intA);
const QVariant &
I think it will construct a variant from the int parameter.
like QVariant var(44) just indirectly.
But a valid Question.
Thanks a lot for the replies but they don´t work
i have tested:
auto intA= QVariant(10);
auto intB= QVariant(20);
but the reply is the same. The result is always 0 :(
JonB last edited by
@nitoman , @mrjj
Then this might sound odd, but I'm not sure there is anything wrong with what you are writing! If the parameters were bad we'd expect an error at the server. So, how do you know the code of that webservice is actually correct and is adding the numbers? The webservice looks pretty "incomplete" (no comments against the other methods supplied), maybe it just does not give the correct answer?! I would try to find some other public webservice somewhere and test passing parameters to that before I assumed anything was wrong in your client code?
Thanks a lot for your support.
i know the webservice is ok because if i test it with a Soap cliente like SopaUI i get a good answer for all operations.
I show an example:
I send this one:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
and i receive:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
the message lose some characters but i think you can see it more or less
Ok, I have solved the problem creating the library with tool "kdwsdl2cpp". Now i have available methods to use the library.
Pablo J. Rogina last edited by
I have solved the problem
great! please mark your post as solved. Thanks.