Many a times we define Apex Webservices inside Salesforce to perform operations on Salesforce data from external world. Anyhow always we are left on how to access these custom defined web services from a WSDL consumer (JAVA/ NET / …)

If we start consuming Parner WSDL only, then we do not get the apex webservice defintions.  Partner WSDL doesn’t contain your custom defined webservice definitions. You’ll also have to cosume Apex Webservice WSDL to call your webservice.

So this involves following 2 steps …

  1. Step1 : Consume Partner WSDL  and then perform Login call to SFDC
  2. binding1 = (SoapBindingStub) new SforceServiceLocator().getSoap();
    loginResult = binding1.login(“username”,”PwdToken”);
    SessionHeader sh = new SessionHeader();

  3. Step2 : Consume Apex Webservice WSDL and Set above fetched SessionId as the sessionHeader on the Apex Webservice WSDL stub and then call the required methods.
  4. binding2 = (checkForLeadNumberBindingStub) new checkForLeadNumberServiceLocator().getcheckForLeadNumber();
    binding2.setHeader(new checkForLeadNumberServiceLocator().getServiceName().getNamespaceURI(), “SessionHeader”, sh);