Important: Please read the Qt Code of Conduct -

Connect To Remote Webservice using Soap

  • I am new to Qt, and in my application i need to connect to a remote service hosted in secure environment. I need to add certificates to the Network request inorder to process the request.

    void QtSoapHttpTransport::submitRequest(QtSoapMessage &request, const QString &path)
    QNetworkRequest networkReq;

    QFile    sslCertificateFile("Certificate1.cer");
    QFile    sslCertificateFileserver("Certificate2.cer");
    QSslConfiguration sslConfiguration;
    QSslCertificate  sslCertificate;
    QSslCertificate  sslCertificateserver;
    if ( ( &&
         // Read certificates from file
         QByteArray aray = sslCertificateFile.readAll();
         qDebug() << aray;
         // Read server ceriticate file
         QByteArray arayserver = sslCertificateFileserver.readAll();
         qDebug() << arayserver;
         // Load Client
         QList<QSslCertificate> sslCertificateList = QSslCertificate::fromData(aray,QSsl::Pem);
         qDebug("Found certificates: %d", sslCertificateList.size());
         sslCertificate = sslCertificateList.takeAt(0);
         QByteArray testarray =  sslCertificate.digest(QCryptographicHash::Sha1);
         qDebug() << testarray;
         // Load Server
         QList<QSslCertificate> sslCertificateListserver = QSslCertificate::fromData(arayserver,QSsl::Der);
         sslCertificateserver = sslCertificateListserver.takeAt(0);
         QList<QSslCertificate> ceritifcates;
         QSslKey key(&sslCertificateFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
         qDebug() << "key isNull ? " << key.isNull();
    networkReq.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml;charset=utf-8"));
    QByteArray array;
    QUrl url2 = path ; 
    networkRep =, request.toXmlString().toUtf8().constData());


    But i am not able to get the Certificate list using "QSslCertificate::fromData(arayserver,QSsl::Der);" . The list is empty. please let me know how to rectify the issue or please suggest any other way to access SSL Certified Service using Qt.

    Note: I have installed Open Ssl and i am configuring it in the project file like below

    CONFIG += openssl
    LIBS += -L"C:/OpenSSL-Win32/lib" -llibeay32

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    if ( ( &&

    You don't do anything in case either files fails to open, at least printing an error message would help find out. Also since your paths are relative, theses two files probably can't be found at run time.

  • Thanks for the suggetions. I would implement them in my application.

    Apart from that my problem still persists. I am able to read the certificate as byte array but i am failing to create QsslCertificate using that certificate.

    I am using QSslCertificate::fromData. but the method is failing to create the certificate. The issue might be caused because fromData method is trying to read
    "-----BEGIN CERTIFICATE-----" macro inside my method. can you please suggest me possible solutions for the issue.

    This logic works fine with .pem certificates however the same logic fails with .cer certificates

  • Lifetime Qt Champion

    You should implement them now, you have somewhere an error occurring and one of them could be that one of these two files (or both) cannot be read but you don't check that. Don't assume it's working, validate.

Log in to reply