function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AK-2AK-2 

Invalid Session ID found in SessionHeader: Illegal Session

I am trying to use an Enterprise WSDL to make an API call from a java client. However, after login is successful, the subsequent calls fail with an error: Invalid session ID found in SessionHeader: Illegal Session. However, the login is successful and I am using the endpoint URL and session id returned by the login. What could be the reason for this error?
Any ideas.

Thank you.
EnreecoEnreeco
Maybe you are not sending the SESSION ID in the header correctly?
AK-2AK-2
Here is the code that I am using to login and then immediately get the time stamp from the server.
I am creating an instance of sessionheader but not sure how to pass that to the subsequent request: 
try {
            service = new SforceService();
            port = service.getSoap();
            
            Login parameters = new Login();
       
            parameters.setUsername(uName);
            parameters.setPassword(p1w0);
            
            ((BindingProvider) port).getRequestContext().put(
                    BindingProvider.SESSION_MAINTAIN_PROPERTY,
                    true);
            
            LoginResponse response = port.login (parameters);
            
            LoginResultType result = response.getResult();
            
            System.out.println("Login was successfull.");
            System.out.print("The returned session id is: ");
            
            //Get session id and server url
            this.sessionID = result.getSessionId();
            
            this.serverURL = result.getServerUrl();
            
            
            userInfo = result.getUserInfo();
            
            //Set server url
            ((BindingProvider) port).getRequestContext().put(
                    BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                    result.getServerUrl());
            

            SessionHeader sessionHdr = new SessionHeader();
            //Get session id and server url
            sessionHdr.setSessionId(result.getSessionId());
            
            
            // Throws exception - SESSION_ID invalid
            port.getServerTimestamp(new GetServerTimestamp());
            GetServerTimestampResponse tsResponse = port.getServerTimestamp(tsParam);
            
            GetServerTimestampResultType tsResult = tsResponse.getResult();
            System.out.println(
                    "Server time is:" + tsResult.getTimestamp().toString());
            
        } catch (InvalidIdFault_Exception ex) {
            
            throw new RuntimeException(ex);
        } catch (LoginFault_Exception ex) {
            throw new RuntimeException(ex);
        } catch (UnexpectedErrorFault_Exception ex) {
            throw new RuntimeException(ex);
        }    
        catch (Exception e){
            throw new RuntimeException(e);
        }