[SalesForce] How to log out from an Apex Webservice

I have got a connection to a salesforce webservice by the following method:

  • Get an EnterpriseConnection to the auth endpoint and so a session id
  • Set the service endpoint to that of the webservice
  • Get a SoapConnection to the web service

Now I'm assuming that I have to log out but am having the following issues:

  • SoapConnection does not have a logout() method.
  • If I try to log out of the EnterpriseConnection using its logout() method, I get the following error message:

com.sforce.ws.SoapFaultException: No operation available for request {urn:enterprise.soap.sforce.com}logout, please check the WSDL for the service

Is there a different way to log out when using webservices than when using just the EnterpriseConnection?

Thanks

EDIT – Addition of code:

public static boolean login() {
    boolean success = false;

    try {
        ConnectorConfig config = new ConnectorConfig();
        config.setUsername(username);
        config.setPassword(password);
        config.setAuthEndpoint(authEndPoint);
        config.setProxy(proxyAddress, 8080);

        enterpriseConnection = com.sforce.soap.enterprise.Connector.newConnection(config); // EnterpriseConnection object

        config.setServiceEndpoint(webserviceEndPoint);
        webserviceConnection = Connector.newConnection(config); // SoapConnectionObject
        webserviceConnection.setSessionHeader(config.getSessionId());

        success = true;
        System.out.print("Logged in to webservice- ");
        Date startTime = new Date();
        System.out.println(DateFormat.getDateTimeInstance().format(startTime));

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

    return success;
}

public static void logout() {

    try {
        enterpriseConnection.logout();
        System.out.print("Logged out - ");
        Date endTime = new Date();
        System.out.println(DateFormat.getDateTimeInstance().format(endTime));

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

Best Answer

Are you sure you are invoking the logout() method from the right Connection object?

Also make sure you are not sending the request to the wrong endpoint.

Enterprise API v/s Partner API.

See:

http://boards.developerforce.com/t5/General-Development/Dreaded-No-operation-available-for-request-on-SOAP-API-call/m-p/377085#M64457

I have used logout() in most of my code especially with C# and Java and never had an issue so far. Do you have any code you can share?

Other things could be the case...it needs to be lowercase. Also please check if your wsdl was saved properly. Does it have a definition for logout()?

Please see:

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_logout.htm

Related Topic