0

I have a piece of code which reads the server certificate and make SSLSocket connection to the server. Following is the code at a high level:

// Create logon request XML in SOAP
SoapObject logonRq = new SoapObject(Constants.NAMESPACE, "LogonRq");
signonRQ.addProperty("UserName", username);
signonRQ.addProperty("Password", passwd);


try {
        HttpsTransportSE transport = new HttpsTransportSE(Constants.Host, Constants.Port, "", 500000);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(org.ksoap2.SoapEnvelope.VER10);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(logonRq);
        envelope.setAddAdornments(false);
        envelope.implicitTypes = true;
        transport.debug = true;

        HttpsServiceConnectionSE sc = (HttpsServiceConnectionSE) transport.getServiceConnection();
        sc.setSSLSocketFactory(GetsslContext.getSSLSocketFactory());
        transport.call(Constants.SOAP_ACTION, envelope);
        SoapObject response = (SoapObject) envelope.bodyIn;

    } catch (Exception e) {
        e.printStackTrace();
    }

Now my requirement is to receive server response and send another client request. For that, do I again need to execute the following?

HttpsTransportSE transport = new HttpsTransportSE(Constants.Host, Constants.Port, "", 500000);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(org.ksoap2.SoapEnvelope.VER10);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(logonRq);
        envelope.setAddAdornments(false);
        envelope.implicitTypes = true;
        transport.debug = true;

        HttpsServiceConnectionSE sc = (HttpsServiceConnectionSE) transport.getServiceConnection();
        sc.setSSLSocketFactory(GetsslContext.getSSLSocketFactory());

transport.call(Constants.SOAP_ACTION, envelope);

Or can I simply call the below statement?

transport.call(Constants.SOAP_ACTION, envelope);

Basically, how can I make my code efficient and ensure I am not making socket/HTTPS calls unnecessarily?

4

0 回答 0