My key concept is: create the SOAP server in the Controller and the methods in the Model. Why? Because controller is … (read this) and model is this.
As an example here we gonna make web service for Post of a Blog (see Blog Tutorial) using native SOAP in PHP version 5.
We’ll put the SOAP handler at URL: http://yourhost/posts/service and the WSDL (which is will be used by the SOAP consumer) at URL: http://yourhost/posts/wsdl.
- Create table Post (see the Blog Tutorial for details).
- Create Post model (models/post.php) as usual.
- Create Post controller (controllers/posts_controller.php), see bellow. You need RequestHandler component for create XML-type response on wsdl action.
- Create view for action “wsdl” (views/posts/wsdl.ctp) and define your service method in it. You can publish all of methods in Post model including from its parent (AppModel), eg. findById(), find(), findAll(), etc. Note: you should turning off “short_open_tag” in php.ini to avoid error on rendering the xml of wsdl view. And don’t forget to define your service address in the WSDL to http://yourhost/posts/service.
- Now your service consumer could consume your service by pointing to your WSDL URL (http://yourhost/posts/wsdl).
Here are the sample codes: Read the rest of this entry »
Recent Comments