PHP Soap Web Service uses SoapDiscovery.class.php to generate WSDL files, _php tutorial

Source: Internet
Author: User

The PHP Soap Web service uses SoapDiscovery.class.php to generate the WSDL file,


The PHP SOAP Web service uses the WSDL file demo:

==============================================================

Service side:

Before using the WSDL Soap WebService demo, use the cw.php file to generate the WSDL file with the following code:

cw.php:

 
  PHPinclude("service.php"); include ("SoapDiscovery.class.php"); $disco New // The first parameter is the name of the class (the generated WSDL file is named after it), the service class, and the second parameter is the name (which can be written casually).  $disco->getwsdl ();

?>

service.php:

 
  PHPinclude_once("soapHandle.class.php"); $server New Array # #此处的Service. wsdl file is the one generated above $server //  $server// processing request ?>

soapHandle.class.php:

 
  PHPclass  soaphandle{    publicfunction strtolink ($url= ") {         return sprintf $url $url );    }          Public function Add ($a$b=2)    {        return$a+ $b ;    }}? >

The SoapDiscovery.class.php code is as follows:

===========================================================

Php /* * * Copyright (c) 2005, Braulio Jos? Solano Rojas * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, is * permitted provided that the FOL Lowing conditions is met: * * redistributions of source code must retain the above copyright notice, this list of * Condi tions and the following disclaimer. * redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following di Sclaimer in the documentation and/or and materials * provided with the distribution. * Neither the name of the Solsoft de Costa Rica S.A. and the names of its contributors may * is used to endorse or promote Products derived from this software without specific * prior written permission. * * This software are provided by the COPYRIGHT holders and * CONTRIBUTORS ' as is ' and any EXPRESS OR implied warranties, * Including, LIMITED to, the implied warranties of * merchantability and FITNESS for A particular PURPOSEis * disclaimed. In NO EVENT shall the COPYRIGHT OWNER OR * CONTRIBUTORS is liable for any DIRECT, INDIRECT, incidental, * special, EXEMPLA RY, or consequential damages (including, but not LIMITED to, procurement of substitute GOODS OR SERVICES; * LOSS of Use, DATA, OR profits; or business interruption) * However caused and on any theory of liability, WHETHER in * contract, STRICT liability, OR TOR T (including negligence OR * OTHERWISE) arising in any-out-of-the---the-software, * Even IF advised of the Possi Bility of SUCH DAMAGE. * * * @version $Id $ * @copyright 2005 */ /* * * soapdiscovery Class that provides Web Service Definition Language (WSDL). * * @package soapdiscovery * @author Bra Ulio Jos? Solano Rojas * @copyright Copyright (c) 2005 Braulio Jos? Solano Rojas * @version $Id $ * @access public * */ class Soapdiscovery { Private $class _name= '' ; Private $service _name= '' ; /* * * SOAPDISCOVERY::__CONSTRUCT () Soapdiscovery class Constructor. * * @param string $class _name * @param string $serv Ice_name * */ Public function__construct ( $class _name= '', $service _name= '' ) { $this->class_name = $class _name ; $this->service_name = $service _name ; } /* * * SOAPDISCOVERY::GETWSDL () Returns The WSDL of a class if the class is instantiable. * * @return String * */ Public function getwsdl () { if( Empty( $this- service_name)) { Throw New Exception(' No service ' name. ' ); } $headerWSDL= " \ n " ; $headerWSDL.= " $this->service_name\ "targetnamespace=\" urn: $this->service_name\ "xmlns:wsdl=\" http://schemas.xmlsoap.org/wsdl/\ "xmlns:soap=\" http://schemas.xmlsoap.org/wsdl /soap/\ "xmlns:tns=\" urn: $this->service_name\ "xmlns:xsd=\" http://www.w3.org/2001/xmlschema\ "xmlns:soap-enc=\" http://schemas.xmlsoap.org/ Soap/encoding/\ "xmlns=\" http://schemas.xmlsoap.org/wsdl/\ ">\n" ; $headerWSDL.= " \ n " ; if( Empty( $this- class_name)) { Throw New Exception(' No class ' name. ' ); } $class= NewReflectionclass ( $this- class_name); if(! $class- isinstantiable ()) { Throw New Exception(' Class is not instantiable. ') ); } $methods= $class- GetMethods (); $portTypeWSDL= ' ' ; $bindingWSDL= ' \ n \ n " ; $serviceWSDL= ' \ nyou $this->service_name. ' Port ' binding= ' TNS: '. $this->service_name. " binding\ "> $_server[' server_name ']. ': '. $_server [' Server_port ']. $_server [' Php_self ']. " \ "/>\n \ n \ n " ; $messageWSDL= '' ; foreach( $methods as $method ) { if( $method->ispublic () &&! $method- Isconstructor ()) { $portTypeWSDL.= ' \ n "." \ n $method->getname (). " Response\ "/>\n \ n " ; $bindingWSDL.= ' \ n "." \ n $this->service_name\ "encodingstyle=\" http://schemas.xmlsoap.org/soap/encoding/\ "/>\n\n \ n $this->service_name\ "encodingstyle=\" http://schemas.xmlsoap.org/soap/encoding/\ "/>\n \ n \ n " ; $messageWSDL.= ' \ n " ; $parameters = $method -getparameters (); foreach ( $parametersas $parameter ) { $messageWSDL. = ' \ n ' ;} /c12>$messageWSDL. = " \ n " ; $messageWSDL.= ' \ n " ; $messageWSDL. = ' \ n ' ; $messageWSDL. = " \ n " ; } } $portTypeWSDL.= " \ n " ; $bindingWSDL.= "\ n " ; // return sprintf ('%s%s%s%s%s%s ', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ' '); $fso= fopen( $this->class_name. ". wsdl", "W" ); fwrite( $fso, sprintf('%s%s%s%s%s%s ', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '' )); } /* * * soapdiscovery::getdiscovery () Returns discovery of WSDL. * * @return String * */ Public function Getdiscovery () { return" \ n \ $_server[' server_name ']. ': '. $_server [' Server_port ']. $_server [' Php_self ']. "? Wsdl\ "/>\n " ; }}?> View Code

Client:

client.php Code:

=============================================================

 
  PHP    ini_set// turn off WSDL cache    $soapnew soapclient ('/HTTP/ LOCALHOST/SOAP/SERVICE.PHP?WSDL ');     Echo $soap->strtolink (' http://www.baidu.com '). "
"; Echo $soap->add (28, 100). "
"; Echo $soap->__soapcall (' Add ',array(28,200)). "
"; // or so call Echo $soap->__call (' Add ',array(28,300)). "
"; Echo Date Time ());? >

================ end====================

http://www.bkjia.com/PHPjc/1119777.html www.bkjia.com true http://www.bkjia.com/PHPjc/1119777.html techarticle The PHP SOAP Web service uses SoapDiscovery.class.php to generate the WSDL file, and the PHP SOAP Web service uses the WSDL file demo: ========================= ===================================== Clothing ...

  • Related Article

    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.