title: Access Salesforce Apex Soap Webservice from Java
body: <p>i'm trying to establish a Connection to my Apex-Webservice but it fails everytime. My Webserce is quite Simple:</p>
  
  <pre><code>global class AtlassianService 
  {
      webService static String hello(String Name) 
      {
          return 'Hello '+Name+' ! :D';
      }
  }
  </code></pre>
  
  <p>To generate the Client i just the way, which is described <a href="http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_steps.htm" rel="nofollow">here</a>:</p>
  
  <pre><code>java –classpath pathToJAR/wsc-22.jar com.sforce.ws.tools.wsdlc pathToWsdl/WsdlFilename​ pathToOutputJar/OutputJarFilename
  </code></pre>
  
  <p>Accessing the Webservice:</p>
  
  <pre><code>SoapConnection soap = Connector.newConnection("mail@XXXXXX.com", "XXXX");
  
  System.out.println(soap.hello("WORLD")); // Invalid Session ( =&gt; SessionID is null)
  </code></pre>
  
  <p>If I use the PartnerConnection to get a valid SessionID everything works fine:</p>
  
  <pre><code>ConnectorConfig config = new ConnectorConfig();
  config.setUsername(username);
  config.setPassword(password);
  config.setAuthEndpoint("https://login.salesforce.com/services/Soap/u/24.0");
  
  new PartnerConnection(config);
  
  SoapConnection soap = Connector.newConnection(null, null);
  soap.setSessionHeader(config.getSessionId());
  
  System.out.println(soap.hello("WORLD"));
  </code></pre>
  
  <p>Anybody has an idea why the first example fails?</p>
  
  <p>Greetings Sebastian</p>