Turning Joomla into a SOAP Server using components

So I am using SugarCRM to feed data into Joomla. I am using SOAP for this purpose but I couldn’t really find any good tutorials on how to set up a soap server in Joomla so I am going to share my implementation here. by the way this is for joomla 2.5 i am sure it is as easy in 3.0 but I haven’t jumped ship yet.

It is actually pretty simple. I will assume you are familiar with creating components for Joomla and that you know SOAP. All you really need is a controller and a separate file with your class that you wish to bind to your SOAP Server.

this is what your controller is going to look like

registerTask('servercall','servercall');
  }
  function servercall(){
      include_once(JPATH_SITE . '/components/com_yourcomponent/controllers/class.sugarfunctions.soap.php');
      try{
        $uri = 'http://yourdomain.net/';
        $server = new SoapServer(null,array('uri'=>$uri));
        $server->setClass('SugarFunctions');
        $server->handle();

      }catch(SoapFault $f){
        // Handle the error
      }
      $app = JFactory::GetApplication();
      $app->close();
  }
}

now you just need to feed your soap client the following URL and that’s it!
Joomla is now a soap server.

http://yourdomain.net/index.php?option=com_YOURCOMPONENT&controller=sugarsoapserver&task=servercall

Of course don’t forget to include the next to your class to protect it from intruders

defined( '_JEXEC' ) or die( 'Restricted access' );

Happy Coding

  1. A coworker stored production assets in Dropbox. Chaos ensued.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.