Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [resolved] How consuming a web service?
Forum Updated to NodeBB v4.3 + New Features

[resolved] How consuming a web service?

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 5.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jeanrl
    wrote on last edited by
    #3

    Thanks for the answers, but I ask another question:

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #4

      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.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jeanrl
        wrote on last edited by
        #5

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #6

          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

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jeanrl
            wrote on last edited by
            #7

            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.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jeanrl
              wrote on last edited by
              #8

              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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on last edited by
                #9

                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);
                @

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jeanrl
                  wrote on last edited by
                  #10

                  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.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andreyc
                    wrote on last edited by
                    #11

                    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.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jeanrl
                      wrote on last edited by
                      #12

                      Ok Andreyc

                      You helped me a lot.

                      Thanks very mouch.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jeanrl
                        wrote on last edited by
                        #13

                        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.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andreyc
                          wrote on last edited by
                          #14

                          Thank you for sharing a solution.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved