[SalesForce] Is it possible to call webservice methods using SOAP API

I'm attempting to create a PHP app that access web service methods through SOAP API calls using the Force.com Toolkit. Currently this is working with REST calls, but as I clean up some things on this project it seems easier if this was available in SOAP.

On the APEX side I have a webservices defined like so:

webservice static myOutputs getSomeAccounts(myInputs inputs){
    // Do stuff to create an output
    return output;
}

Then on the PHP side I have my app defined like so:

class MyApp {

    protected $client

    function __construct(){
        # Standard connection based on documentation
        $sf_connector = new SalesforceConnector();
        # Return SforcePartnerClient object from ForceTK
        $this->client = $sf_connector->client; 

    }

    # Web service request   // DOESN'T WORK
    function webserviceTest(){
        $response = $this->client->getSomeAccounts($params);
        # getSomeAccounts() is not recognized by the client...
        # Hoping for something like $this->client->webservice('getSomeAccounts');
    }

    # Query test      // WORKS
    function query(){
        $query = "SELECT Id, FirstName, LastName, Phone from Contact LIMIT 10";
        $response = $this->client->query($query);
        $queryResult = new QueryResult($response);

        for ($queryResult->rewind(); $queryResult->pointer < $queryResult->size; $queryResult->next()) {
            $record = $queryResult->current();
            echo $record->Id.": ".$record->fields->FirstName." ".$record->fields->LastName." ".$record->fields->Phone."<br/>\n";
        }
    }
}

Is it not possible to do what I want through SOAP? Or is this just a limitation of the Force.com Toolkit? First time working with SOAP and feel like I'm grasping things fine just not sure how to make this request.

Thanks for the help

Best Answer

This is likely a limitation of how SOAP and the Force.com Toolkit work.

SOAP APIs work by defining a WSDL that describes all the allowed API calls along with their expected parameters and return types.

The Force.com Toolkit will be built upon the Partner API. This is generic API for doing CRUD type operations and checking dynamic metadata to see what objects and fields the connected org exposes.

What the Partner API doesn't do in it's WSDL is expose your custom getSomeAccounts Apex web service method. To consume that you will need to generate the WSDL for the parent Apex class and then interact with that in the appropriate way from PHP. What the appropriate way is for PHP I don't know.

You could probably use the Force.com Toolkit as a boiler plate for how to make the API call. The custom WSDL and the Partner API share many common types. E.g. you will be able to use the Session ID from the Partner API in the headers of your custom Apex web service.

Related Topic