Qt-based BB10 API Examples Documentation

Contents

QtSoapHttpTransport Class Reference

The QtSoapHttpTransport class provides a mechanism for transporting SOAP messages to and from other hosts using the HTTP protocol. More...

    #include <QtSoapHttpTransport>

Inherits: QObject.

Public Functions

QtSoapHttpTransport ( QObject * parent = 0 )
~QtSoapHttpTransport ()
const QtSoapMessage & getResponse () const
QNetworkAccessManager * networkAccessManager ()
QNetworkReply * networkReply ()
void setAction ( const QString & action )
void setHost ( const QString & host, bool useSecureHTTP = false, int port = 0 )
void submitRequest ( QtSoapMessage & request, const QString & path )

Signals

void responseReady ()
void responseReady ( const QtSoapMessage & response )

Additional Inherited Members

Detailed Description

The QtSoapHttpTransport class provides a mechanism for transporting SOAP messages to and from other hosts using the HTTP protocol.

Use this class to submit SOAP messages to a web service. Set the hostname of the SOAP server with setHost(). Some servers also require the SOAPAction header to be set, and you can do this with setAction(). Next, submit the request with submitRequest(), passing the message to submit together with the path that you want to submit the message to. The responseReady() signal is emitted when a response has been received. Call getResponse() to get the reponse from the service.

QtSoapHttpTransport usage example: If a SOAP weather service was running on the host weather.example.com, the following code might be used to find the temperature in any given city:

    void WeatherFetcher::findTemperature(const QString &city)
    {
        QtSoapMessage message;
        message.setMethod("getTemperature", "http://weather.example.com/temperature");
        message.setMethodArgument("city", "", city);

        // transport is a private member of WeatherFetcher, of type QtSoapHttpTransport
        transport.setHost("www.example.com");
        connect(&transport, SIGNAL(responseReady()), SLOT(readResponse()));

        transport.submitRequest(message, "/weatherfetcher/fetch.asp");
    }

This is an example implementation of the readResponse() slot in the WeatherFetcher class:

    void WeatherFetcher::readResponse()
    {
        const QtSoapMessage &response = transport.getResponse();
        if (response.isFault()) {
            cout << response.faultString().toString().toLatin1().constData() << endl;
            return;
        }

        const QtSoapType &returnValue = response.returnValue();
        if (returnValue["temperature"].isValid()) {
        cout << "The current temperature is "
             << returnValue["temperature"].toString().toLatin1().constData()
             << " degrees Celcius." << endl;
    }

See also QtSoapMessage and QtSoapType.

Member Function Documentation

QtSoapHttpTransport::QtSoapHttpTransport ( QObject * parent = 0 )

Constructs a QtSoapHttpTransport object. Passes parent to QObject's constructor.

QtSoapHttpTransport::~QtSoapHttpTransport ()

Destructs a QtSoapHttpTransport.

const QtSoapMessage & QtSoapHttpTransport::getResponse () const

Returns the most recently received response SOAP message. This message could be a Fault message, so it is wise to check using QtSoapMessage::isFault() before processing the response.

QNetworkAccessManager * QtSoapHttpTransport::networkAccessManager ()

Returns a pointer to the QNetworkAccessManager object used by this transport. This is useful if the application needs to connect to its signals, or set or read its cookie jar, etc.

QNetworkReply * QtSoapHttpTransport::networkReply ()

Returns a pointer to the QNetworkReply object of the current (or last) request, or 0 if no such object is currently available.

This is useful if the application needs to access the raw header data etc.

void QtSoapHttpTransport::responseReady () [signal]

This signal is emitted when a SOAP response is received from a remote peer.

See also getResponse().

void QtSoapHttpTransport::responseReady ( const QtSoapMessage & response ) [signal]

This signal is emitted when a SOAP response is received from a remote peer. The received response is available in response. This signal is emitted in tandem with the argument-less responseReady() signal.

See also responseReady().

void QtSoapHttpTransport::setAction ( const QString & action )

Sets the HTTP header SOAPAction to action.

void QtSoapHttpTransport::setHost ( const QString & host, bool useSecureHTTP = false, int port = 0 )

Sets the host this transport should connect to. The transport mode will be HTTP, unless useSecureHTTP is set, in which case it will be HTTPS. This transport will connect to the well-known ports by default (80 for HTTP, 443 for HTTPS), unless a different, non-zero port is specified in port.

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

Submits the SOAP message request to the path path on the HTTP server set using setHost().