We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37059
    • 368 Posts
    I am using MODx to create an application that will process data, store it, and serve it up via a basic SOAP interface. If necessary, I can put the SOAP server outside of MODx, but I would much prefer to put it inside a snippet so that it will be able to access the data through xPDO objects.

    So far, I am in the early stages of learning about SOAP. Following online tutorials, I have gotten a basic SOAP server/client setup going on the development box, with server and client living in their own PHP files outside of MODx. I now am trying to take this same code and place it in a snippet, which is called on the page /server (using friendly URL's). Here is the snippet code:

    (This, by the way, is a valid snippet - part of my 'spiadmin' component. It will work with a minimal "return 'hello world'" example.)

    <?php
    $spi = $modx->getService('spiadmin','Spiadmin',$modx->getOption('core_path').'components/spiadmin/model/spiadmin/',$scriptProperties);
    if (!($spi instanceof Spiadmin)) return '';
    
    $quotes = array(
    
      "ibm" => 98.42
    
    );  
    
    function getQuote($symbol) {
    
      global $quotes;
    
      return $quotes[$symbol];
    
    }
    
    ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
    
    $server = new SoapServer("stockquote.wsdl");
    
    $server->addFunction("getQuote");
    
    $server->handle();
    


    Most of this is directly copy/pasted from the SOAP server tutorial I'm using.

    The SOAP client fails silently when directed to /server through the WSDL file. Here's what /server outputs when accessed directly:

    Notice: ob_end_clean(): failed to delete buffer default output handler. in ... {usual filenames, call stacks etc.}
    


    Can someone tell me:

    • What does that error mean?
    • Is what I want to do - run a SOAP server from inside MODx - even possible?



    [ed. note: polrbear last edited this post 13 years, 9 months ago.]
      Jason
      • 37059
      • 368 Posts
      [bump]

      I'm still wondering about this. Anybody?
        Jason
        • 37059
        • 368 Posts
        Well, we are finding a way to do this, sort of. Right now an approach that seems to work is to place the SOAP server in a separate file, but include the MODx class with API mode activated so that we have access to all the MODx objects. If anyone finds this thread and is interested, PM me and I will send you the details.
          Jason
          • 22303 MODX Staff
          • 10,725 Posts
          If using inside MODX, and you intend to handle the SOAP output and exit the process yourself, rather than just setting the appropriate content/content type and letting MODX send the response, you will need to wipe out the output buffer's first...

          I assume this is what your handle() method is doing. Try calling this before calling handle()...

          while (@ob_end_clean()) {}


          This will make sure all output buffers are closed (and contents thrown away) before your method handles the response.
            • 37059
            • 368 Posts
            Wow! That totally works, and so simple! I just added that line above $server->handle() per your suggestion, and the whole thing sprang back to life. Abundant thanks for the help laugh
              Jason
              • 42675
              • 1 Posts
              Quote from: polrbear at Oct 12, 2012, 09:15 AM
              Well, we are finding a way to do this, sort of. Right now an approach that seems to work is to place the SOAP server in a separate file, but include the MODx class with API mode activated so that we have access to all the MODx objects. If anyone finds this thread and is interested, PM me and I will send you the details.


              Yes i am, i was trying to do the same as you but as a newbie in Modx i can't set the service for now
                • 37059
                • 368 Posts
                Quote from: macjpster at Feb 05, 2013, 11:43 PM

                Yes i am, i was trying to do the same as you but as a newbie in Modx i can't set the service for now

                Did you try OpenGeek's solution above? We switched over to that when he posted it. It much simpler and cleaner than what we were doing.
                  Jason