Solved Example with KDSoap
-
Hi.
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.
Regards.
-
@nitoman
I'm afraid I don't know KDSoap. But look at http://www.dneonline.com/calculator.asmx?op=Add, where you can see what POST content that method expects:<?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 anAdd
node at the top-level, and then make parameters children of that.EDIT Whoops, no, I see,
client.call(QLatin1String("Add"), message);
passes theAdd
. And the response shows are getting anAddResult
back. Sorry! I'm having a rethink... :)KDSoap, https://docs.kdab.com/kdsoap/1.0.0/class_k_d_soap_message.html#a465ae2c13f2c3c26e19aeb01d10b89d8:
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 aQVariant
variable holding anint
for this to work, likeauto intA = QVariant::QVariant(10); message.addArgument(QLatin1String("intA"), intA);
?
-
@JonB said in Example with KDSoap:
const QVariant &
Hi
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);message.addArgument(QLatin1String("intA"), intA);
message.addArgument(QLatin1String("intN"), intB);but the reply is the same. The result is always 0 :(
-
@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? -
Hi jonB.
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/">
soapenv:Header/
soapenv:Body
tem:Add
tem:intA10</tem:intA>
tem:intB10</tem:intB>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>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">
soap:Body
<AddResponse xmlns="http://tempuri.org/">
<AddResult>20</AddResult>
</AddResponse>
</soap:Body>
</soap:Envelope> -
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.
Thanks!
-
@nitoman said in Example with KDSoap:
I have solved the problem
great! please mark your post as solved. Thanks.