PDA

View Full Version : QTSoapMessage Question



ken123
23rd July 2010, 19:26
I want to create a SOAP message based on the following XM file:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://www.remotereality.com/HubbleSOAP.xsd3"
xmlns:ns3="http://www.remotereality.com/HubbleSOAP/binding/cameracontrol"
xmlns:ns4="http://www.remotereality.com/HubbleSOAP/binding/videoprocamp"
xmlns:ns5="http://www.remotereality.com/HubbleSOAP/binding/jpegCODEC"
xmlns:ns6="http://www.remotereality.com/HubbleSOAP/binding/viewcontrol"
xmlns:ns7="http://www.remotereality.com/HubbleSOAP/binding/KSPropertySet">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<ns6:SetAngles>
<index>0</index>
<yaw>0.0</yaw>
<pitch>0.0</pitch>
<roll>0.0</roll>
</ns6:SetAngles>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I am a newbie when it comes to SOAP. Could anybody show me in detail using the QTSoapMessage class on how to do it? Thanks.

ken123
23rd July 2010, 21:17
Never mind, I got it now. Any example for parsing the QTSoapMessage? Thanks.

wysota
23rd July 2010, 21:56
http://doc.qt.nokia.com/solutions/4/qtsoap/google-example.html

ken123
26th July 2010, 18:34
http://doc.qt.nokia.com/solutions/4/qtsoap/google-example.html

In the getResponse method, all I got are the method names, but no data are shown. There is something wrong with the parser.

void Google::getResponse()
{
// Set cursor back to normal shape.
QApplication::restoreOverrideCursor();

// Reset resultView.
resultView->clear();

// Get the response, check for error.
const QtSoapMessage &resp = http.getResponse();
if (resp.isFault()) {
resultView->setHtml(tr("<b>Query failed</b>: ")
+ resp.faultString().value().toString());
return;
}

// Extract the return value from this method response, check for
// errors.
const QtSoapType &res = resp.returnValue();
if (!res.isValid()) {
resultView->append(tr("Invalid return value"));
return;
}

// Generate resultView output. Make it resemble the actual web
// output from http://www.google.com/.
QString header(tr("Searched the web for <b>%1</b>, results %2 - %3 "
"of about %4. Search took %5 seconds.<br><hr>")
.arg(res["searchQuery"].toString())
.arg(res["startIndex"].toInt())
.arg(res["endIndex"].toInt())
.arg(res["estimatedTotalResultsCount"].toInt())
.arg(res["searchTime"].value().toDouble(), 0, 'f', 2));

const QtSoapType &resultElements = res["resultElements"];
QString allElements;

for (int i = 0; i < resultElements.count(); ++i) {
const QtSoapType &resultElement = res["resultElements"][i];

QString cat = resultElement["directoryCategory"]["fullViewableName"].toString();
QString summary = resultElement["summary"].toString();
QString title = resultElement["title"].toString();
QString snippet = resultElement["snippet"].toString();
QString url = resultElement["URL"].toString();
QString cachedSize = resultElement["cachedSize"].toString();

QString thisElement = "<br>";

if (!title.isEmpty()) {
thisElement += "<font color=\"#0000FF\"><b><u>"
+ title + "</u></b></font><br>";
} else {
thisElement += "<font color=\"#0000FF\"><b><u>"
+ url + "</u></b></font><br>";
}

if (!snippet.isEmpty())
thisElement += snippet + "<br>";

if (!summary.isEmpty()) {
thisElement += "<font color=\"#808080\">Description:</font> "
+ summary + "<br>";
}

if (!cat.isEmpty()) {
thisElement += "<font color=\"#808080\">Category: <u>"
+ cat + "</u></font><br>";
}

if (!title.isEmpty()) {
thisElement += "<font color=\"#008000\"><u>" + url
+ "</u> - " + cachedSize + "</font><br>";
}

allElements += thisElement;
}

// Update the resultView.
resultView->setHtml(header + allElements);
}

ken123
26th July 2010, 18:41
Here are my xml response data:

<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/">
<GetFieldOfViewResponse xmlns="http://www.remotereality.com/HubbleSOAP/binding/viewcontrol">
<HRESULT xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" >0</HRESULT>
<d1 xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" >6.2831853071795862</d1>
<d2 xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" >0</d2>
</GetFieldOfViewResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I got the method name, but with no data at all.

Here are my codes:

void MainWindow::getResponse()
{
const QtSoapMessage &message = http.getResponse();
if (message.isFault()) {
return;
}

const QtSoapType &response= message.returnValue();
qDebug("Data are: %s)",
response["HRESULT"].value().toString().toLatin1().constData(),
response["d1"].value().toString().toLatin1().constData(),
response["d2"].value().toString().toLatin1().constData());
}