[resolved] How consuming a web service?



  • People I need to query a Web Service, but I have no experience in it. I've tried several ways, but I can't, if someone can give me a light will be very grateful.

    The site that I read here:
    https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl

    And using SoapUI I got to see all the services, one for you to have idea is this:

    @
    <soapenv: Envelope xmlns: soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: cli = "http://cliente.bean.master.sigep.bsb.correios.com.br/" >
        <soapenv: Header />
        <soapenv: Body>
           <cli: buscaCliente>
              <idContrato> 9912208555 </ idContrato>
              <idCartaoPostagem> 0067594867 </ idCartaoPostagem>
              <User> SIGEP </ User>
              <password> n5f9t8 </ password>
           </ cli: buscaCliente>
        </ soapenv: Body>
    </ soapenv: Envelope>
    @

    And the query via SoapUI works perfectly, so I know it's working, but do not know how to implement in Qt.

    Thanks you all.

    Solution:

    @
    QByteArray arr;
    arr.append(leXML());

    QNetworkRequest request;
    request.setUrl(
              QUrl("https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl"));
    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) ));
    QSslConfiguration sslConf = request.sslConfiguration();
    sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
    request.setSslConfiguration(sslConf);
    
    
    m_manager.post(request,arr);
    
    connect(&m_manager,SIGNAL(finished(QNetworkReply*)),this,
                SLOT(slotRequestFinished(QNetworkReply*)));
    

    @





  • Thanks for the answers, but I ask another question:

    Is not it better to use native or better KD Soap?



  • What do you mean "native".
    Qt does not have a built-in support for SOAP. You can implement it using "QtXml":http://qt-project.org/doc/qt-5/qtxml-index.html
    Another option is to use third party solution. One of them is KDSOAP.

    [quote author="jeanrl" date="1417466935"]
    Is not it better to use native or better KD Soap?[/quote]
    Do you want to implement SOAP yourself? If yes then "native" is the way. If not then use KDSOAP or other solutions.



  • It is thought that using the QNetworkmanager, QNetworkReply and QtXml I can do without third-party tools, but as I said before, I'm a little lost so I asked what the best option: Native or KDSOAP?

    But both one way as the other I need an example, because I have no idea how to do.

    Thanks.



  • I think you need to familiarize yourself with SOAP.
    After that you will be able to choose between doing it yourself or using thirdparty tools.
    As for the examples: "kd soap example":https://github.com/KDAB/KDSoap/tree/master/examples
    or "Qt networking and xml example":http://qt-project.org/doc/qt-5/qtnetwork-googlesuggest-example.html



  • Yes, you are correct, I need to familiarize myself with SOAP.

    I'll see the two examples calmly to try to understand.

    Again thank you for your attention.

    PS I will not close the topic, it may appear more an opinion.



  • I'm trying to adapt the example proposed by friend here in this thread, but I'm having an error that I have no idea how to solve.

    Can anyone tell me what's going on where I am going wrong?

    Is giving error: "SSL handshake failed"

    The code is:
    @

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);

    networkManager.get(QNetworkRequest(QString("https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl")));
    
    connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(slotRequestFinished(QNetworkReply*)));
    

    }

    void Widget::slotRequestFinished(QNetworkReply *networkReply)
    {
    qDebug() << "Chegou Final";

    QUrl url = networkReply->url();
    
    if (!networkReply->error())
    {
        QStringList choices;
        QStringList hits;
    
        QByteArray response(networkReply->readAll());
    
        qDebug() << "response " << response;
    
    
        QXmlStreamReader xml(response);
        while (!xml.atEnd()) {
            xml.readNext();
            
            qDebug() < ...;
    
        }
    }
    else
        qDebug() << "erro no reply " << networkReply->errorString();
    
    
    networkReply->deleteLater();
    

    }
    @

    Thanks.



  • Firefox says:
    @
    apphom.correios.com.br uses an invalid security certificate. The certificate is not trusted because no issuer chain was provided. (Error code: sec_error_unknown_issuer)
    @
    If you know this site and does not worry about wrong certificate then you can disable SSL verification for now.
    @
    QNetworkRequest request(QString("https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl");
    QSslConfiguration sslConf = request.sslConfiguration();
    sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
    request.setSslConfiguration(sslConf);
    networkManager.get(request);
    @



  • Perfect, it worked.
    This site is the postal service here in Brazil, so no problems with the certificate.

    One more question:

    In that reply I have all the services available, but how do I consume these services? I know I have to send a xml with the parameters, but do not know how, can you give me an idea of how to do this?

    Thank you very much.

    P.S. I'm sorry if I seem to be taking advantage, is not found virtually no material on the Internet, especially for those who have no experience with Web Service with Qt.



  • I never used SOAP in practice so don't know exactly.
    I guess you need to send a request to some url with an XML body that has parameters.



  • Ok Andreyc

    You helped me a lot.

    Thanks very mouch.



  • It finally worked:

    @
    QNetworkRequest request;
    request.setUrl(
    QUrl("https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl"));
    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) ));
    QSslConfiguration sslConf = request.sslConfiguration();
    sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
    request.setSslConfiguration(sslConf);

    m_manager.post(request,xml);
    
    connect(&m_manager,SIGNAL(finished(QNetworkReply*)),this,
                SLOT(slotRequestFinished(QNetworkReply*)));
    

    @

    Thanks again Andreyc.



  • Thank you for sharing a solution.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.