QT: Connect to SOAP Webservice

Hello Friends,

Here, I hereby trying to show an example for How to send SOAP Post request through QT?.
To create a Qt client application that connects to a SOAP/WSDL web service, I have used QT 4.7


XML packet:


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetFullDetails xmlns="http://core-1.doubleu.mobi/MecaniqueWS">
    </GetFullDetails>
  </soap:Body>
</soap:Envelope>
 
QString XMLData = <Your XML Packet> 
MyClass obj; 
QString returnData =  obj.httpcall(XMLData);
 
 
Create MyClass.cpp
 
QString MyClass::httpcall(QString data)
{
    connect(m_manager,SIGNAL(finished(QNetworkReply*)),this, 
            SLOT(httpdown(QNetworkReply*)));

    QByteArray arr;
    arr.append(data);
    QNetworkRequest request;
    request.setUrl(
              QUrl("http://core-1.doubleu.mobi/Mecaniquews/service/mecanique.asmx?
              op=GetFullDetails"));
    request.setHeader( QNetworkRequest::ContentTypeHeader, 
                       QVariant( QString("text/xml;charset=utf-8")));
    request.setHeader(QNetworkRequest::ContentLengthHeader,
                      QVariant( qulonglong(arr.size()) ));
    request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
                         QVariant( int(QNetworkRequest::AlwaysNetwork) ));
    m_manager->post(request,arr);
    return NULL;
}
 
void MyClass::httpdown(QNetworkReply* result)
{
    if(result->error() == QNetworkReply::NoError)
    {
        if(MainWindow::isConfirm == true)
        {
            QByteArray dataResult= result->readAll();
            QString std(dataResult);
            stringdata = std;
            qDebug()<<stringdata;
    }
} 
 
 
Hope this may helpful to you.
Cheers!!! 
 

Comments

Popular posts from this blog

Intercept HOME Key: Android

Wisdom of Work