Implementing SOAP with WSDL in PHP

Source: Internet
Author: User
Tags wsdl

  1. Install the libraries required to generate the WSDL with composer

    Composer require Piotrooo/wsdl-creator
  2. The
  3. Implements a portal file for external access, and the code example refers to a class name that appears in the method name and parameter in Notify , and the method of that class becomes the external interface that can be called by SOAP):

    <?phpuse wsdl\documentliteralwrapper;use wsdl\wsdlcreator;use Wsdl\xml\styles\documentliteralwrapped;class Api        {public static function soapnotify () {$host = $_server[' http_host ');        $soapuri = "http://{$host}/api/soapnotify";            if (Isset ($_get[' WSDL '))) {$wsdl = new Wsdlcreator (' Notify ', $soapuri);            $WSDL->renderwsdl ();        Exit        } $server = new SoapServer (null, [' uri ' = = $soapuri]);        $server->setclass (' Notify ');    $server->handle (); }}
  4. To implement a class file that contains the interface's functional logic, please refer to the code example (where the annotation of the method is very important and is the basis for wsdl-creator to correctly generate the WSDL, which must be commented in strict format):

    Class notify{    /**     * @desc sendText send text message to patient     * @param string $toUser to which user     * @param string $content sent within Capacity     * @return string $result     *    /Public Function SendText ($toUser, $content)    {        if (! $toUser | |!$ Content) {            return e::invalid;        }        $user = G::xpdo ()->row ("Select * from ' users ' WHERE ' patientid ' =?", [$toUser]);        if (! $user) {            return e::nodata;        }        $api = G::xpdo ()->row ("SELECT * from ' API ' WHERE ' token ' =? ', [$user [' token ']]);        $weixin = new Weixin ($api [' AppID '], $api [' Appsecret ']);        $weixin->sendtext ($user [' OpenID '], $content);        return 0;}    }
  5. Debugging an interface using the SoapUI software

  6. Preparing the appropriate interface invocation documentation

Resources:

    • For the basic document structure of SOAP, refer to http://www.sitepoint.com/series/creating-web-services-with-php-and-soap/]
    • About the library that generates the WSDL wsdl-creator see: Https://github.com/piotrooo/wsdl-creator

Implementing SOAP with WSDL in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.