PDA

View Full Version : Qt SOAP: parsing response message



newb_developer
22nd June 2012, 18:35
Hello,
I have the following Qt SOAP getresponse code:


void MainWindow::getResponse()
{
/*
* Get a reference to a response message.
*/
const QtSoapMessage &message = http.getResponse();

/*
* Check if the message is a SOAP Fault message.
*/
if(message.isFault()) {
QMessageBox::critical(this, "Error", message.faultString().toString());
return;
} else {
// print the return value
const QtSoapType &response = message.returnValue();
ui->textEdit->setText(response["GetWhoISResult"].value().toString().toLatin1().constData());
}
}


I get the following response XML message: I'd like to convert it's GetWhoISResult to QString, then display it in QTextBox.
ui->textEdit->setText(message.toXmlString());


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<GetWhoISResponse xmlns="http://www.webservicex.net">
<GetWhoISResult xmlns="http://www.webservicex.net" xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">previous request is being processed for 173.201.44.188</GetWhoISResult>
</GetWhoISResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


This code fails:
ui->textEdit->setText(response["GetWhoISResult"].value().toString().toLatin1().constData());
I get nothing.

How can I try to solve this?

wysota
22nd June 2012, 20:05
Try response.value().toString()

newb_developer
22nd June 2012, 22:21
It doesn't help.

I modified code:



void MainWindow::getResponse()
{
/*
* Get a reference to a response message.
*/
const QtSoapMessage &message = http.getResponse();

/*
* Check if the message is a SOAP Fault message.
*/
if(message.isFault()) {
QMessageBox::critical(this, "Error", message.faultString().toString());
return;
} else {
// print the return value
const QtSoapType &response = message.returnValue();
if(response["GetWhoISResult"].isValid())
ui->textEdit->setText(response["GetWhoISResult"].value().toString());
else {
QMessageBox::critical(this, "Info", response.errorString());
ui->textEdit->setText(message.toXmlString());
}
}


Got error:
"Unknown error"

XML message:


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<GetWhoISResponse xmlns="http://www.webservicex.net">
<GetWhoISResult xmlns="http://www.webservicex.net" xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
DOMAIN NAME: wp.pl&#xd;
registrant type: organization&#xd;
nameservers: ns2.wp.pl. [153.19.102.182]&#xd;
ns1.wp.pl. [212.77.102.200]&#xd;
ns1.task.gda.pl. [153.19.250.101]&#xd;
created: 1998.04.28 13:00:00&#xd;
last modified: 2008.12.18 10:11:20&#xd;
renewal date: 2013.04.27 14:00:00&#xd;
&#xd;
option created: 2011.01.27 17:08:58&#xd;
option expiration date: 2014.01.27 17:08:58&#xd;
&#xd;
dnssec: Unsigned&#xd;
&#xd;
&#xd;
REGISTRAR:&#xd;
NASK&#xd;
ul. Wawozowa 18&#xd;
02-796 Warszawa&#xd;
Polska/Poland&#xd;
+48.22 3808300&#xd;
info@dns.pl&#xd;
&#xd;
WHOIS displays data with a delay not exceeding 15 minutes in relation to the .pl Registry system&#xd;
Registrant data available at http://dns.pl/cgi-bin/en_whois.pl</GetWhoISResult>
</GetWhoISResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


If I type a name of wrong SOAP object I get the same: "Unknown error". However, it seems to me that "GetWhoISResult" is what I need.

wysota
22nd June 2012, 22:58
Cast the response object to QtSoapStruct and use the latter's class API to access the proper member of the structure.

newb_developer
23rd June 2012, 00:33
I tried:


/*
* Get a reference to a response message.
*/
const QtSoapMessage &message = http.getResponse();

/*
* Check if the message is a SOAP Fault message.
*/
if(message.isFault()) {
QMessageBox::critical(this, "Error", message.faultString().toString());
return;
} else {
// print the return value
const QtSoapType &response = message.returnValue();

ui->textEdit->setText((QtSoapStruct)response["GetWhoISResponse"]);
}


Compile error:

C2440: 'type cast' : cannot convert from 'const QtSoapType' to 'QtSoapStruct'
No constructor could take the source type, or constructor overload resolution was ambiguous

wysota
23rd June 2012, 01:11
If you have a const object then cast it to a const type. If it doesn't work then you need to do the conversion to QtSoapStruct indirectly somehow. I remember fixing something in QtSoap for my own needs but I don't remember if it was related to that cast or not, it was a couple of years ago.