Since I added the web service to my Drupal site, some new operations have been added to the SOAP service. I don't see them showing up in the web service. I'm going to remove and readd the service. I did not make a lot of config changes on existing operations in Drupal and my calls to the service are in code. So I shouldn't lose too much this time. But it would be nice to just be able to hit a Refresh button on the service and have it re-read the WSDL and pull in the new operations.

Comments

dman’s picture

Using the web service test module includes a (silent) feature to 'flush' the WSDL cache each request - FYI.

alfaguru’s picture

+1 for this. Once a SOAP web service has been added there's no obvious way to update its stored definition from the WSDL other than by deleting and recreating it, which if it's been added to a feature is long-winded to say the least.

Flushing the WSDL cache won't change the definition stored, will it? So that'll still be out of step with the remote.

dman’s picture

Yeah you are right, flushing the WSDL only affects a PHP-level cache thing.
As pretty much any change that may happen to the remote service could include a full rewrite : operations or datatypes may be added, deleted or changed during a refresh - it is pretty necessary to delete the entire service and re-initialize it from scratch each time.

I did that 10 times in succession last week when testing a change. Wasn't too hard with the browser memory remembering my endpoint URL in the textfield, but it's true a single button would have saved me three clicks each time...

alexku’s picture

We are using following snippet in our current project:

/**
 * Implements hook_wsclient_service_update().
 *
 * Refreshes SOAP service operations and datatypes when a service description is saved.
 * Related to https://www.drupal.org/node/2269661
 */
function [MODULE_NAME]_wsclient_service_update($service) {
  if ($service->name ==[SERVICE_NAME] && !$service->endpointUpdated) {
    $endpoint = $service->endpoint();
    $endpoint->initializeMetadata();
    $service->endpointUpdated = TRUE; // set a flag to avoid infite recursion
    $service->save();
    rules_clear_cache();
    $service->clearCache();
    drupal_set_message(t('Operations and data types of the SOAP service have been re-imported automatically. If the service expects data types with propertie
  }
}

CAUTION: this wipes out any custom changes on each submit of a specific service

I could create a patch adding a checkbox to service configuration form. If set, service configuration would be refresh on submit. Would this be useful?

joelpittet’s picture

Thanks @alexku, that seemed to work well. Just had to update it a bit so that features update didn't try to override it.


function MODULE_import_wsclient_service_update($service) {
  // Check user access so that this doesn't get called for features update.
  if (user_access('administer web services') && $service->name =='SERVICE_NAME' && !empty($service->endpointUpdated)) {
    // Set a flag to avoid inifinite recursion.
    $service->endpointUpdated = TRUE; 
    $endpoint = $service->endpoint();
    $endpoint->initializeMetadata();
    $service->save();
    rules_clear_cache();
    $service->clearCache();
    drupal_set_message(t('Operations and data types of the SOAP service have been re-imported automatically.'));
  }
}