TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
kohana and web services
  • hi guys,

    just want to pick your brains, has anyone served web services using kohana? if so any advice? I have to use kohana to provide information to Flex and Air apps through WSDL described services, id like to hear if anyone else does something similar.

  • I didn't set up Flex or Air, I've just tried a few months ago the SOAP features offered by PHP 5. It worked quite good though it's in experimental state.
  • thanks for the reply spirit,

    anyone else have experience with the above? id like to know if theres anything i should be careful of, or if people have experience of xml_rpc, soap or rest with kohana and which they would recommend implementing.

  • Soon I will be implementing some sort of RPC for (mainly) python front-ends to a K2.1 app. I would also like to know which library would be best to use.
  • NuSOAP looks good dougal.
  • Use the built-in SOAP library, it will be faster, if nothing else.

  • Ive used PHP5's built in SOAP Library and it couldnt be easier, the only thing i find annoying is the generation of the .wsdl file but other then that its easy.
  • I've built a web api for communicating with a cairngorm structured flex application (REST using JSON). At some point I will push the api back in to the community as I think the user login and dynamic api-key functionality will be useful for a lot of situations. But if you have any questions let me know.

    Once the data is in flex its very easy to manipulate it (especially if you use XML). But the most useful thing I can suggest is before you try and capture the information in Flex, create a php page which emulates the same functionality as the flex app. This will make debugging a LOT easier. You can use something like curl to emulate the requests. I have a page which basically is a series of unit tests which will call all the methods of the api. The requests and responses are then traced out. Once a method is working on the test php page, I then drop it into flex, already knowing exactly what the response and request will look like.

  • One more thing. Spend a bit of time organising the format of the request to match Flex value objects. This is something I did not do at the start of my project because I didn't believe Flex would be able to convert the data so well, but its actually very clever how it works.

  • Thanks for all your help guys!

    @ae - good tip regarding the php emulate page, will do that alright.

    spent the day yesterday seeing how easy it was to communicate between flex and php by just binding xml to flex objects. i was surprised by how nicely it all fell together. seems very promising. once i get into it and understand it completely i'll do a write up on it.
  • Well, I've done some research today on using Kohana as a webservice. I've been comparing SOAP to XML-RPC and seeing what needs to be done on both the server and client side for either system to work. There are, of course, pros and cons to both.
    For SOAP, I used the NuSOAP library, and for xml-rpc I used the phpxml-roc library, and not the php extension.

    Here's my conclusions so far.

    A very capable mechanism, but for the purposes of my project may be impractical due to requirement of installing a SOAP library with the client.

    Pretty easy to set up on the server side.
    Worked with existing PHP functions, all data type conversion is transparent.
    SoapUI program makes debugging very easy, and automates test-cases, complete with HTTP session management.

    Requires 3 python libraries to be installed alongside the client program. Probably beyond most end-users. this is a very big Con.
    Required a small investigation to get raw POST to wsdl service, solution:

    $HTTP_RAW_POST_DATA = file_get_contents("php://input");

    Requires some additional stub methods to register with service.

    I was able to set up a service providing is_logged_in(), login($u,$p), and logout() methods, and sucessfully start, maintain and close an authenticated user session.... and pretty quickly too.

    A much more 'hands-on' approach. Not much in the way of transparent data handling, though a much simpler concept to implement.

    Client side libraries exist in default python installation (xmlrpclib).
    Server declaration routine is much simpler.

    Had to write my own test client script (in python). (haven't yet figured out HTTP session handling, and therefore not yet completed the user login/logout exercise).
    Requires wrappers for every php function to expose, requiring manual handling of xmlrpc* data objects.

    I've spent the majority of today trying to figure out a good way to "wrap" existing functions in my app for xmlrpc use. Trying to implement this would require much duplication of existing code. The automatic "wrapper" functions in the library did not work.

    I'm still undecided. I'm sure there are some concepts and methods left to explore that will resolve some of the problems I am facing right now.
    However, I would really like to get xml-rpc working as it'll make the end-user's lives easier - and this will be a big waste of time if nobody can figure out how to use the webservice once it's built!
  • thanks for the info dougal.
  • Phew... more struggles with xmlrpc libraries, and upgrading this app to 2.3...

    My advice for anyone wanting to implement xmlrpc in a 2.3 app:

    Forget native xmlrpc library - it's too "manual". If you're using Kohana, then you're probably better off with an xmlrpc implementation, not the basic methods.
    Forget PHPXMLRPC ( http://phpxmlrpc.sourceforge.net/ ) - it's not at all OOP, and after an hour or more of trying to refactor it for 2.3 I gave up... left it in many small pieces on the floor.

    I've had success running NuSOAP.
    To use NuSOAP I had to put class Nusoap_all {} in the nusoap_all.php file and rename/move it to "libs"/nusoap/classes/nusoap/all.php
    Then create a dummy obejct $ns_loader = new Nusoap_all(); in your controller before using the nusoap classes.

    Now for the best find ever.... "Incutio XML-RPC" ( http://scripts.incutio.com/xmlrpc/manual.php ). what a nice library :)
    I split the IXR_Library.inc.php file into separate class files in "libs"/ixr/classes/ixr/{base64, client, clientmulticall, date, error, introspectionserver, message, request, server, value}.php - only to find NOTHING left over. It's all perfectly OOP.

    It only leaves me wishing that PHP had multiple inheritance so that I could extends Controller, IXR_Server .. but alas I have to create an app_server extends IXR_Server and instantiate it in my xmlrpc controller. Also, there's no awkward type conversions, it's all handled perfectly.

    It works very well, and is so far the winning solution.
  • someone should rewrite IXR for K. :-)

    i'll give it a try. maybe you can see it in my cms soon
  • It would be pretty trivial to alter the IXR library so that the IXR_Server class extends Controller and calls parent:GDN__construct() in it's constructor. Then we'd have xmlrpc enabled Controllers :)

    [thinking aloud]
    The slight problem comes with the fact that Controllers usually output HTML, which is useless to an xmlrpc client which is expecting data.

    Perhaps IXR_Server should extend Model ?
    However the Kohana app entry point is always a controller.
    Therefore, there will always be method duplication for xmlrpc methods.
    [/thinking aloud]

    hmm. let me think about this, I'm still figuring it out.
  • My suggestion is to use the PHP bindings for SOAP as last time i checked nusoap hadnt been updated in well over a year.
    Its very basic to understand even for a beginner, although when making a server the WSDL can be abit of an annoyance.
  • I just use xml helper that automates output (arrays) to xml.... I have been waiting on the release of the Zend AMFPHP library... http://framework.zend.com/wiki/display/ZFPROP/Zend_Amf+-+Wade+Arnold
  • Hi,

    Has anyone implemented PHP SOAP extension under Kohana?

    I was able to create a prototype using an pre-created wsdl (Eclipse WSDL editor) outside of Kohana framework, however it doesn't seem to work under Kohana framework.

    Kohana Implementation:

    1) Created WSDL file (Eclipse WSDL editor) - place it under new directory called WS under the root.
    2) Created a class (not inheriting from controller nor model) that has a method defined in the WSDL.
    3) Created a Controller class - index() method instantiates the SOAPServer object based on the WSDL and maps to the class (from #2).
    4) Used Soap Client to validate the Web Service. It just times out.

  • Hi,

    I want to know , How install the soap in Kohana 3.3.1 . I need sample code for installation.

  • @Siva using SOAP \ WSDL in Kohana has no special differences. Translate and read http://habrahabr.ru/post/187390/ and http://www.w3.org/2003/03/Translations/byTechnology?technology=soap12-part0. Create basic SOAP controller (extended Controller_Template) to create and display SOAP content (XML), add extended your SOAP controller.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion