+ Start a Discussion

Trying to logout gives No operation available for request {urn:enterprise.soap.sforce.com}logout

I assume the problem has to do with how I'm setting the session header after logging in.

public class LoginLogout {
  private static final Scanner scanner = new Scanner (System.in);

  public static void main (String... args) throws Exception {
    final SoapBindingStub soapBinding = (SoapBindingStub) new SforceServiceLocator ().getSoap ();
    final LoginResult loginResult;
    final String userName = getInput ("User");
    final String password = getInput ("Password");

    soapBinding.setTimeout (60000);
    loginResult = soapBinding.login (userName, password);

    if (loginResult.isPasswordExpired ()) {
      System.out.println ("An error has occurred. Your password has expired.");
      throw new ServiceException ("Login failed. Password expired");

    final SessionHeader sh = new SessionHeader ();
    sh.setSessionId (loginResult.getSessionId ());

    soapBinding._setProperty (SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getMetadataServerUrl ());
    soapBinding.setHeader (new SforceServiceLocator ().getServiceName ().getNamespaceURI (), "SessionHeader", sh);

    soapBinding.logout ();

  private static String getInput (final String prompt) {
    System.out.println (prompt + ": ");
    return scanner.nextLine ();

Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultString: No operation available for request {urn:enterprise.soap.sforce.com}logout
{http://xml.apache.org/axis/}stackTrace:No operation available for request {urn:enterprise.soap.sforce.com}logout
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)

etc. ...


Why are you setting the URL to the metadataServerUrl ? the metadata API has no logout method.
D'OH! Thanks.

This actually bring up a related question though. I've been copy/pasting the setting of the URL and session header, and usually I've seen

soapBinding.setHeader (
  new SforceServiceLocator ().getServiceName ().getNamespaceURI (), 
  "SessionHeader", sh);


but then in some sample code for the query call, I saw

new SforceServiceLocator().getServiceName().getNamespaceURI(),
"QueryOptions", qo);

The MetadataServer/Server snafu was kind of a no-brainer, but for the header, is there documentation somewhere that gives some explanation so that I don't have to just copy paste what the given sample tells me? Or are there no other special cases--just SessionHeader at login an QueryOptions when querying with SOQL?

The API docs has details on all the headers. QueryOptions is used with Query, but is not actually required.
Ah, sho 'nuff. All I had to do was scroll down a little further, or collapse some of the nav menu.